From ffa2a0c9eaa81b040e034b0d3490ae56b078664b Mon Sep 17 00:00:00 2001 From: bbernays Date: Wed, 1 Feb 2023 11:52:05 -0600 Subject: [PATCH 1/6] Update testing.go --- plugins/source/testing.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/source/testing.go b/plugins/source/testing.go index 8aa1e99215..63a6500d71 100644 --- a/plugins/source/testing.go +++ b/plugins/source/testing.go @@ -12,7 +12,8 @@ func TestPluginSync(t *testing.T, plugin *Plugin, spec specs.Source, opts ...Tes t.Helper() o := &testPluginOptions{ - parallel: true, + parallel: true, + validators: []func(t *testing.T, tables schema.Tables, resources []*schema.Resource){validateTables}, } for _, opt := range opts { opt(o) @@ -40,8 +41,10 @@ func TestPluginSync(t *testing.T, plugin *Plugin, spec specs.Source, opts ...Tes if syncErr != nil { t.Fatal(syncErr) } + for _, validator := range o.validators { + validator(t, plugin.Tables(), syncedResources) + } - validateTables(t, plugin.Tables(), syncedResources) } type TestPluginOption func(*testPluginOptions) @@ -52,8 +55,15 @@ func WithTestPluginNoParallel() TestPluginOption { } } +func WithTestPluginAdditionalValidators(v func(t *testing.T, tables schema.Tables, resources []*schema.Resource)) TestPluginOption { + return func(f *testPluginOptions) { + f.validators = append(f.validators, v) + } +} + type testPluginOptions struct { - parallel bool + parallel bool + validators []func(t *testing.T, tables schema.Tables, resources []*schema.Resource) } func getTableResources(t *testing.T, table *schema.Table, resources []*schema.Resource) []*schema.Resource { From e28ae4089bc43f8ea6487e4c0a8e86cddd1db273 Mon Sep 17 00:00:00 2001 From: bbernays Date: Wed, 1 Feb 2023 11:54:30 -0600 Subject: [PATCH 2/6] Update testing.go --- plugins/source/testing.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/source/testing.go b/plugins/source/testing.go index 63a6500d71..3ef54bde67 100644 --- a/plugins/source/testing.go +++ b/plugins/source/testing.go @@ -44,7 +44,6 @@ func TestPluginSync(t *testing.T, plugin *Plugin, spec specs.Source, opts ...Tes for _, validator := range o.validators { validator(t, plugin.Tables(), syncedResources) } - } type TestPluginOption func(*testPluginOptions) From 8275f56bd78271c8df683bd0276f818a942beaf9 Mon Sep 17 00:00:00 2001 From: bbernays Date: Mon, 6 Feb 2023 15:14:09 -0500 Subject: [PATCH 3/6] Update testing.go --- plugins/source/testing.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/source/testing.go b/plugins/source/testing.go index 3ef54bde67..4b23a82b60 100644 --- a/plugins/source/testing.go +++ b/plugins/source/testing.go @@ -8,12 +8,14 @@ import ( "github.com/cloudquery/plugin-sdk/specs" ) +type Validator func(t *testing.T, tables schema.Tables, resources []*schema.Resource) + func TestPluginSync(t *testing.T, plugin *Plugin, spec specs.Source, opts ...TestPluginOption) { t.Helper() o := &testPluginOptions{ parallel: true, - validators: []func(t *testing.T, tables schema.Tables, resources []*schema.Resource){validateTables}, + validators: []Validator{validateTables}, } for _, opt := range opts { opt(o) @@ -54,7 +56,7 @@ func WithTestPluginNoParallel() TestPluginOption { } } -func WithTestPluginAdditionalValidators(v func(t *testing.T, tables schema.Tables, resources []*schema.Resource)) TestPluginOption { +func WithTestPluginAdditionalValidators(v Validator) TestPluginOption { return func(f *testPluginOptions) { f.validators = append(f.validators, v) } @@ -62,7 +64,7 @@ func WithTestPluginAdditionalValidators(v func(t *testing.T, tables schema.Table type testPluginOptions struct { parallel bool - validators []func(t *testing.T, tables schema.Tables, resources []*schema.Resource) + validators []Validator } func getTableResources(t *testing.T, table *schema.Table, resources []*schema.Resource) []*schema.Resource { From 805d884e8bfe912819a89642165a9c232b43690e Mon Sep 17 00:00:00 2001 From: bbernays Date: Tue, 7 Feb 2023 08:24:04 -0500 Subject: [PATCH 4/6] Update testing.go --- plugins/source/testing.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/source/testing.go b/plugins/source/testing.go index 4b23a82b60..e84020c223 100644 --- a/plugins/source/testing.go +++ b/plugins/source/testing.go @@ -8,14 +8,14 @@ import ( "github.com/cloudquery/plugin-sdk/specs" ) -type Validator func(t *testing.T, tables schema.Tables, resources []*schema.Resource) +type Validator func(t *testing.T, plugin *Plugin, resources []*schema.Resource) func TestPluginSync(t *testing.T, plugin *Plugin, spec specs.Source, opts ...TestPluginOption) { t.Helper() o := &testPluginOptions{ parallel: true, - validators: []Validator{validateTables}, + validators: []Validator{validatePlugin}, } for _, opt := range opts { opt(o) @@ -44,7 +44,7 @@ func TestPluginSync(t *testing.T, plugin *Plugin, spec specs.Source, opts ...Tes t.Fatal(syncErr) } for _, validator := range o.validators { - validator(t, plugin.Tables(), syncedResources) + validator(t, plugin, syncedResources) } } @@ -91,6 +91,14 @@ func validateTable(t *testing.T, table *schema.Table, resources []*schema.Resour validateResources(t, tableResources) } +func validatePlugin(t *testing.T, plugin *Plugin, resources []*schema.Resource) { + t.Helper() + for _, table := range plugin.tables { + validateTable(t, table, resources) + validateTables(t, table.Relations, resources) + } +} + func validateTables(t *testing.T, tables schema.Tables, resources []*schema.Resource) { t.Helper() for _, table := range tables { From 80be260753e4c8c292c03998de5702cca70b5f6c Mon Sep 17 00:00:00 2001 From: bbernays Date: Tue, 7 Feb 2023 08:36:10 -0500 Subject: [PATCH 5/6] Update testing.go --- plugins/source/testing.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/source/testing.go b/plugins/source/testing.go index e84020c223..add8e5f3d2 100644 --- a/plugins/source/testing.go +++ b/plugins/source/testing.go @@ -93,18 +93,19 @@ func validateTable(t *testing.T, table *schema.Table, resources []*schema.Resour func validatePlugin(t *testing.T, plugin *Plugin, resources []*schema.Resource) { t.Helper() - for _, table := range plugin.tables { + tables := extractTables(plugin.tables) + for _, table := range tables { validateTable(t, table, resources) - validateTables(t, table.Relations, resources) } } -func validateTables(t *testing.T, tables schema.Tables, resources []*schema.Resource) { - t.Helper() +func extractTables(tables schema.Tables) []*schema.Table { + var result []*schema.Table for _, table := range tables { - validateTable(t, table, resources) - validateTables(t, table.Relations, resources) + result = append(result, table) + result = append(result, extractTables(table.Relations)...) } + return result } // Validates that every column has at least one non-nil value. From 5902ff19313fb056d2e5fda7c5dd15d1a1e8adf1 Mon Sep 17 00:00:00 2001 From: bbernays Date: Tue, 7 Feb 2023 09:02:25 -0500 Subject: [PATCH 6/6] Update testing.go --- plugins/source/testing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/source/testing.go b/plugins/source/testing.go index add8e5f3d2..6f96196341 100644 --- a/plugins/source/testing.go +++ b/plugins/source/testing.go @@ -100,7 +100,7 @@ func validatePlugin(t *testing.T, plugin *Plugin, resources []*schema.Resource) } func extractTables(tables schema.Tables) []*schema.Table { - var result []*schema.Table + result := make([]*schema.Table, 0) for _, table := range tables { result = append(result, table) result = append(result, extractTables(table.Relations)...)