From e157520932feeb1cfa99dc960ded5fc332f75513 Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Tue, 14 Nov 2023 12:20:57 +0200 Subject: [PATCH 1/4] fix: Mark relations as paid as well --- premium/tables.go | 1 + 1 file changed, 1 insertion(+) diff --git a/premium/tables.go b/premium/tables.go index 2f9a8217ba..abf263a884 100644 --- a/premium/tables.go +++ b/premium/tables.go @@ -23,5 +23,6 @@ func MakeAllTablesPaid(tables schema.Tables) schema.Tables { // MakeTablePaid sets the table to paid func MakeTablePaid(table *schema.Table) *schema.Table { table.IsPaid = true + MakeAllTablesPaid(table.Relations) return table } From 32842b62901d8573be376c7ceaf80f5fe0cd5637 Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Tue, 14 Nov 2023 12:27:03 +0200 Subject: [PATCH 2/4] add test --- premium/tables_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/premium/tables_test.go b/premium/tables_test.go index 251be02d0b..5da642209c 100644 --- a/premium/tables_test.go +++ b/premium/tables_test.go @@ -1,9 +1,10 @@ package premium import ( + "testing" + "github.com/cloudquery/plugin-sdk/v4/schema" "github.com/stretchr/testify/assert" - "testing" ) func TestContainsPaidTables(t *testing.T) { @@ -28,12 +29,22 @@ func TestMakeAllTablesPaid(t *testing.T) { &schema.Table{Name: "table1", IsPaid: false}, &schema.Table{Name: "table2", IsPaid: false}, &schema.Table{Name: "table3", IsPaid: false}, + &schema.Table{Name: "table_with_relations", IsPaid: false, Relations: schema.Tables{ + &schema.Table{Name: "relation_table", IsPaid: false}, + }}, } paidTables := MakeAllTablesPaid(noPaidTables) - assert.Equal(t, 3, len(paidTables)) - for _, table := range paidTables { + assert.Equal(t, 4, len(paidTables)) + assert.Equal(t, 5, len(paidTables.FlattenTables())) + assertAllArePaid(t, paidTables) +} + +func assertAllArePaid(t *testing.T, tables schema.Tables) { + t.Helper() + for _, table := range tables { assert.True(t, table.IsPaid) + assertAllArePaid(t, table.Relations) } } From 1f68a1b3d5691367cf951427a64e91f0a427b19c Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Tue, 14 Nov 2023 12:31:44 +0200 Subject: [PATCH 3/4] add comment --- premium/tables.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/premium/tables.go b/premium/tables.go index abf263a884..2127d1f86f 100644 --- a/premium/tables.go +++ b/premium/tables.go @@ -12,7 +12,7 @@ func ContainsPaidTables(tables schema.Tables) bool { return false } -// MakeAllTablesPaid sets all tables to paid +// MakeAllTablesPaid sets all tables to paid (including relations) func MakeAllTablesPaid(tables schema.Tables) schema.Tables { for _, table := range tables { MakeTablePaid(table) @@ -20,7 +20,7 @@ func MakeAllTablesPaid(tables schema.Tables) schema.Tables { return tables } -// MakeTablePaid sets the table to paid +// MakeTablePaid sets the table to paid (including relations) func MakeTablePaid(table *schema.Table) *schema.Table { table.IsPaid = true MakeAllTablesPaid(table.Relations) From 21d6090d2e0f1a97e7e8e02807516243516703ec Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Tue, 14 Nov 2023 12:33:37 +0200 Subject: [PATCH 4/4] remove `MakeTablePaid` --- premium/tables.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/premium/tables.go b/premium/tables.go index 2127d1f86f..ec8884fbff 100644 --- a/premium/tables.go +++ b/premium/tables.go @@ -15,14 +15,8 @@ func ContainsPaidTables(tables schema.Tables) bool { // MakeAllTablesPaid sets all tables to paid (including relations) func MakeAllTablesPaid(tables schema.Tables) schema.Tables { for _, table := range tables { - MakeTablePaid(table) + table.IsPaid = true + MakeAllTablesPaid(table.Relations) } return tables } - -// MakeTablePaid sets the table to paid (including relations) -func MakeTablePaid(table *schema.Table) *schema.Table { - table.IsPaid = true - MakeAllTablesPaid(table.Relations) - return table -}