11package client
22
33import (
4- "context"
54 "os"
65 "testing"
7- "time"
86
97 "github.com/cloudquery/plugin-sdk/plugins"
10- "github.com/cloudquery/plugin-sdk/specs"
11- "github.com/rs/zerolog"
128)
139
14- func getTestLogger (t * testing.T ) zerolog.Logger {
15- t .Helper ()
16- zerolog .TimeFieldFormat = zerolog .TimeFormatUnixMs
17- return zerolog .New (zerolog .NewTestWriter (t )).Output (
18- zerolog.ConsoleWriter {Out : os .Stderr , TimeFormat : time .StampMicro },
19- ).Level (zerolog .DebugLevel ).With ().Timestamp ().Logger ()
20- }
21-
2210func getTestConnection () string {
2311 testConn := os .Getenv ("CQ_DEST_PG_TEST_CONN" )
2412 if testConn == "" {
@@ -27,43 +15,16 @@ func getTestConnection() string {
2715 return testConn
2816}
2917
30- func TestInitialize (t * testing.T ) {
31- ctx := context .Background ()
32- client , err := New (ctx , getTestLogger (t ), specs.Destination {
33- Spec : Spec {
34- ConnectionString : getTestConnection (),
35- },
36- })
37- if err != nil {
38- t .Fatal (err )
39- }
40- if client == nil {
41- t .Fatal ("client is nil" )
42- }
43- if err := client .Close (ctx ); err != nil {
44- t .Fatal (err )
45- }
46- err = client .Close (ctx )
47- if err == nil {
48- t .Fatal ("expected error when closing a closed client second time" )
49- }
50-
51- if err .Error () != "client already closed or not initialized" {
52- t .Fatal ("expected error when closing a closed client second time" )
53- }
54- }
55-
5618func TestPgPlugin (t * testing.T ) {
57- ctx := context .Background ()
5819 p := plugins .NewDestinationPlugin ("postgresql" , "development" , New )
59-
60- if err := plugins .DestinationPluginTestHelper (ctx , p , getTestLogger (t ), specs.Destination {
61- WriteMode : specs .WriteModeAppend ,
62- Spec : Spec {
20+ plugins .DestinationPluginTestSuiteRunner (t , p ,
21+ Spec {
6322 ConnectionString : getTestConnection (),
6423 PgxLogLevel : LogLevelTrace ,
6524 },
66- }); err != nil {
67- t .Fatal (err )
68- }
25+ plugins.DestinationTestSuiteTests {
26+ Overwrite : true ,
27+ Append : true ,
28+ DeleteStale : true ,
29+ })
6930}
0 commit comments