@@ -2,14 +2,13 @@ package client
22
33import (
44 "context"
5- "fmt"
65 "os"
76 "testing"
87 "time"
98
10- "github.com/cloudquery/plugin-pb-go/specs "
11- "github.com/cloudquery/plugin-sdk/v3/plugins/source "
12- "github.com/cloudquery/plugin-sdk/v3 /schema"
9+ "github.com/cloudquery/plugin-sdk/v4/message "
10+ "github.com/cloudquery/plugin-sdk/v4/scheduler "
11+ "github.com/cloudquery/plugin-sdk/v4 /schema"
1312 "github.com/golang/mock/gomock"
1413 "github.com/rs/zerolog"
1514)
@@ -19,49 +18,41 @@ const (
1918 TestZoneID = "test_zone"
2019)
2120
22- func MockTestHelper (t * testing.T , table * schema.Table , builder func (* testing.T , * gomock.Controller ) Clients ) {
23- version := "vDev"
21+ func filterInserts (msgs message.SyncMessages ) message.SyncInserts {
22+ inserts := []* message.SyncInsert {}
23+ for _ , msg := range msgs {
24+ if m , ok := msg .(* message.SyncInsert ); ok {
25+ inserts = append (inserts , m )
26+ }
27+ }
28+ return inserts
29+ }
2430
31+ func MockTestHelper (t * testing.T , table * schema.Table , builder func (* testing.T , * gomock.Controller ) Clients ) {
2532 t .Helper ()
2633 table .IgnoreInTests = false
2734
2835 ctrl := gomock .NewController (t )
2936 defer ctrl .Finish ()
30- logger := zerolog .New (zerolog .NewTestWriter (t )).Output (
37+ l := zerolog .New (zerolog .NewTestWriter (t )).Output (
3138 zerolog.ConsoleWriter {Out : os .Stderr , TimeFormat : time .StampMicro },
3239 ).Level (zerolog .DebugLevel ).With ().Timestamp ().Logger ()
33-
34- newTestExecutionClient := func (ctx context.Context , _ zerolog.Logger , spec specs.Source , _ source.Options ) (schema.ClientMeta , error ) {
35- var cfSpec Spec
36- if err := spec .UnmarshalSpec (& cfSpec ); err != nil {
37- return nil , fmt .Errorf ("failed to unmarshal cloudflare spec: %w" , err )
38- }
39-
40- clients := builder (t , ctrl )
41- c := New (logger , clients , clients [TestAccountID ], AccountZones {
42- TestAccountID : {
43- AccountId : TestAccountID ,
44- Zones : []string {TestZoneID },
45- },
46- })
47-
48- return c .withZoneID (TestAccountID , TestZoneID ), nil
49- }
50-
51- p := source .NewPlugin (
52- table .Name ,
53- version ,
54- []* schema.Table {
55- table ,
40+ sched := scheduler .NewScheduler (scheduler .WithLogger (l ))
41+ clients := builder (t , ctrl )
42+ c := New (l , clients , clients [TestAccountID ], AccountZones {
43+ TestAccountID : {
44+ AccountId : TestAccountID ,
45+ Zones : []string {TestZoneID },
5646 },
57- newTestExecutionClient ,
58- )
59- p .SetLogger (logger )
60- source .TestPluginSync (t , p , specs.Source {
61- Name : "dev" ,
62- Path : "cloudquery/dev" ,
63- Version : version ,
64- Tables : []string {table .Name },
65- Destinations : []string {"mock-destination" },
6647 })
48+
49+ messages , err := sched .SyncAll (context .Background (), & c , schema.Tables {table })
50+ if err != nil {
51+ t .Fatalf ("failed to sync: %v" , err )
52+ }
53+ records := filterInserts (messages ).GetRecordsForTable (table )
54+ emptyColumns := schema .FindEmptyColumns (table , records )
55+ if len (emptyColumns ) > 0 {
56+ t .Fatalf ("empty columns: %v" , emptyColumns )
57+ }
6758}
0 commit comments