@@ -11,18 +11,17 @@ import (
1111 "time"
1212
1313 "github.com/gorilla/mux"
14+ "github.com/rs/zerolog"
1415
1516 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
1617 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
1718 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
1819 "github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1920 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/billing/armbilling"
2021 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
21- "github.com/cloudquery/plugin-pb-go/specs"
22- "github.com/cloudquery/plugin-sdk/v3/faker"
23- "github.com/cloudquery/plugin-sdk/v3/plugins/source"
24- "github.com/cloudquery/plugin-sdk/v3/schema"
25- "github.com/rs/zerolog"
22+ "github.com/cloudquery/plugin-sdk/v4/faker"
23+ "github.com/cloudquery/plugin-sdk/v4/scheduler"
24+ "github.com/cloudquery/plugin-sdk/v4/schema"
2625)
2726
2827const TestSubscription = "12345678-1234-1234-1234-123456789000"
@@ -68,7 +67,7 @@ func (c *MockHttpClient) Do(req *http.Request) (*http.Response, error) {
6867}
6968
7069func MockTestHelper (t * testing.T , table * schema.Table , createServices func (* mux.Router ) error ) {
71- version := "vDev"
70+ // version := "vDev"
7271 t .Helper ()
7372 debug = true
7473 table .IgnoreInTests = false
@@ -102,57 +101,55 @@ func MockTestHelper(t *testing.T, table *schema.Table, createServices func(*mux.
102101 billingPeriod .ID = to .Ptr ("/subscriptions/" + TestSubscription + "/providers/Microsoft.Billing/billingPeriods/202205-1" )
103102
104103 l := zerolog .New (zerolog .NewTestWriter (t )).Output (zerolog.ConsoleWriter {Out : os .Stderr , TimeFormat : time .StampMicro }).Level (zerolog .DebugLevel ).With ().Timestamp ().Logger ()
105- newTestExecutionClient := func (ctx context.Context , logger zerolog.Logger , spec specs.Source , _ source.Options ) (schema.ClientMeta , error ) {
106- err := createServices (router )
107- if err != nil {
108- return nil , err
109- }
110- registeredNamespaces := make (map [string ]map [string ]bool )
111- registeredNamespaces [TestSubscription ] = make (map [string ]bool )
112- for _ , namespace := range namespaces {
113- registeredNamespaces [TestSubscription ][namespace ] = true
114- }
115-
116- resourceGroup := & armresources.ResourceGroup {}
117- err = faker .FakeObject (resourceGroup )
118- if err != nil {
119- return nil , err
120- }
121- resourceGroup .Name = & testResourceGroup
122-
123- c := & Client {
124- logger : l ,
125- Options : & arm.ClientOptions {
126- ClientOptions : policy.ClientOptions {
127- Transport : mockClient ,
128- },
129- },
130- registeredNamespaces : registeredNamespaces ,
131- Creds : creds ,
132- subscriptions : []string {TestSubscription },
133- ResourceGroups : map [string ][]* armresources.ResourceGroup {
134- TestSubscription : {resourceGroup },
135- },
136- BillingAccounts : []* armbilling.Account {& legacyAccount , & modernAccount },
137- BillingPeriods : map [string ][]* armbilling.Period {
138- TestSubscription : {& billingPeriod },
139- },
140- storageAccountKeys : & sync.Map {},
141- pluginSpec : & Spec {
142- NormalizeIDs : true ,
143- },
144- }
145104
146- return c , nil
105+ err := createServices (router )
106+ if err != nil {
107+ t .Fatal (err )
108+ }
109+ registeredNamespaces := make (map [string ]map [string ]bool )
110+ registeredNamespaces [TestSubscription ] = make (map [string ]bool )
111+ for _ , namespace := range namespaces {
112+ registeredNamespaces [TestSubscription ][namespace ] = true
147113 }
148114
149- p := source .NewPlugin (table .Name , version , []* schema.Table {table }, newTestExecutionClient )
150- p .SetLogger (l )
151- source .TestPluginSync (t , p , specs.Source {
152- Name : "dev" ,
153- Path : "cloudquery/dev" ,
154- Version : version ,
155- Tables : []string {table .Name },
156- Destinations : []string {"mock-destination" },
157- })
115+ resourceGroup := & armresources.ResourceGroup {}
116+ err = faker .FakeObject (resourceGroup )
117+ if err != nil {
118+ t .Fatal (err )
119+ }
120+ resourceGroup .Name = & testResourceGroup
121+
122+ c := & Client {
123+ logger : l ,
124+ Options : & arm.ClientOptions {
125+ ClientOptions : policy.ClientOptions {
126+ Transport : mockClient ,
127+ },
128+ },
129+ registeredNamespaces : registeredNamespaces ,
130+ Creds : creds ,
131+ subscriptions : []string {TestSubscription },
132+ ResourceGroups : map [string ][]* armresources.ResourceGroup {
133+ TestSubscription : {resourceGroup },
134+ },
135+ BillingAccounts : []* armbilling.Account {& legacyAccount , & modernAccount },
136+ BillingPeriods : map [string ][]* armbilling.Period {
137+ TestSubscription : {& billingPeriod },
138+ },
139+ storageAccountKeys : & sync.Map {},
140+ pluginSpec : & Spec {
141+ NormalizeIDs : true ,
142+ },
143+ }
144+ sched := scheduler .NewScheduler (scheduler .WithLogger (l ))
145+ messages , err := sched .SyncAll (context .Background (), c , schema.Tables {table })
146+ if err != nil {
147+ t .Fatalf ("failed to sync: %v" , err )
148+ }
149+
150+ records := messages .GetInserts ().GetRecordsForTable (table )
151+ emptyColumns := schema .FindEmptyColumns (table , records )
152+ if len (emptyColumns ) > 0 {
153+ t .Fatalf ("empty columns: %v" , emptyColumns )
154+ }
158155}
0 commit comments