|
| 1 | +package example |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/sivaosorg/govm/dbx" |
| 7 | + "github.com/sivaosorg/govm/logger" |
| 8 | + "github.com/sivaosorg/govm/postgres" |
| 9 | + "github.com/sivaosorg/psqlconn" |
| 10 | +) |
| 11 | + |
| 12 | +func createConn() (*psqlconn.Postgres, dbx.Dbx) { |
| 13 | + return psqlconn.NewClient(*postgres.GetPostgresConfigSample(). |
| 14 | + SetDebugMode(false). |
| 15 | + SetEnabled(true). |
| 16 | + SetPort(6666). |
| 17 | + SetUsername("tms_admin"). |
| 18 | + SetDatabase("db"). |
| 19 | + SetPassword("Usfy3siOO%fX")) |
| 20 | +} |
| 21 | + |
| 22 | +func TestConn(t *testing.T) { |
| 23 | + _, s := createConn() |
| 24 | + logger.Infof("Postgres connection status: %v", s) |
| 25 | +} |
| 26 | + |
| 27 | +func TestServiceTables(t *testing.T) { |
| 28 | + p, _ := createConn() |
| 29 | + svc := psqlconn.NewPostgresService(p) |
| 30 | + tables, err := svc.Tables() |
| 31 | + if err != nil { |
| 32 | + logger.Errorf("Fetching all tables got an error", err) |
| 33 | + return |
| 34 | + } |
| 35 | + logger.Infof("All tables: %v", tables) |
| 36 | +} |
| 37 | + |
| 38 | +func TestServiceFunctions(t *testing.T) { |
| 39 | + p, _ := createConn() |
| 40 | + svc := psqlconn.NewPostgresService(p) |
| 41 | + functions, err := svc.FunctionsDescriptor() |
| 42 | + if err != nil { |
| 43 | + logger.Errorf("Fetching all functions got an error", err) |
| 44 | + return |
| 45 | + } |
| 46 | + logger.Infof("All functions: %v", functions) |
| 47 | +} |
| 48 | + |
| 49 | +func TestServiceProduces(t *testing.T) { |
| 50 | + p, _ := createConn() |
| 51 | + svc := psqlconn.NewPostgresService(p) |
| 52 | + functions, err := svc.ProceduresDescriptor() |
| 53 | + if err != nil { |
| 54 | + logger.Errorf("Fetching all procedures got an error", err) |
| 55 | + return |
| 56 | + } |
| 57 | + logger.Infof("All procedures: %v", functions) |
| 58 | +} |
| 59 | + |
| 60 | +func TestServiceFunctionDescriptor(t *testing.T) { |
| 61 | + p, _ := createConn() |
| 62 | + svc := psqlconn.NewPostgresService(p) |
| 63 | + tables, err := svc.FunctionDescriptor("get_activelead_v7") |
| 64 | + if err != nil { |
| 65 | + logger.Errorf("Fetching function descriptor got an error", err) |
| 66 | + return |
| 67 | + } |
| 68 | + logger.Infof("Function descriptor: %v", tables) |
| 69 | +} |
| 70 | + |
| 71 | +func TestServiceFunctionTypeDescriptor(t *testing.T) { |
| 72 | + p, _ := createConn() |
| 73 | + svc := psqlconn.NewPostgresService(p) |
| 74 | + tables, err := svc.FunctionDDescriptor("get_activelead_v7") |
| 75 | + if err != nil { |
| 76 | + logger.Errorf("Fetching function descriptor got an error", err) |
| 77 | + return |
| 78 | + } |
| 79 | + logger.Infof("Function descriptor: %v", tables) |
| 80 | +} |
| 81 | + |
| 82 | +func TestServiceTableTypeDescriptor(t *testing.T) { |
| 83 | + p, _ := createConn() |
| 84 | + svc := psqlconn.NewPostgresService(p) |
| 85 | + desc, err := svc.TableDescriptor("or_user") |
| 86 | + if err != nil { |
| 87 | + logger.Errorf("Fetching table descriptor got an error", err) |
| 88 | + return |
| 89 | + } |
| 90 | + logger.Infof("Table descriptor: %v", desc) |
| 91 | +} |
| 92 | + |
| 93 | +func TestServiceTableDescriptor(t *testing.T) { |
| 94 | + p, _ := createConn() |
| 95 | + svc := psqlconn.NewPostgresService(p) |
| 96 | + desc, err := svc.TableInfo("or_user") |
| 97 | + if err != nil { |
| 98 | + logger.Errorf("Fetching table info got an error", err) |
| 99 | + return |
| 100 | + } |
| 101 | + logger.Infof("Table info: %v", desc) |
| 102 | +} |
0 commit comments