Skip to content

Commit ca833eb

Browse files
authored
fix: Mark relations as paid as well (#1366)
1 parent 2ec138f commit ca833eb

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

premium/tables.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@ func ContainsPaidTables(tables schema.Tables) bool {
1212
return false
1313
}
1414

15-
// MakeAllTablesPaid sets all tables to paid
15+
// MakeAllTablesPaid sets all tables to paid (including relations)
1616
func MakeAllTablesPaid(tables schema.Tables) schema.Tables {
1717
for _, table := range tables {
18-
MakeTablePaid(table)
18+
table.IsPaid = true
19+
MakeAllTablesPaid(table.Relations)
1920
}
2021
return tables
2122
}
22-
23-
// MakeTablePaid sets the table to paid
24-
func MakeTablePaid(table *schema.Table) *schema.Table {
25-
table.IsPaid = true
26-
return table
27-
}

premium/tables_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package premium
22

33
import (
4+
"testing"
5+
46
"github.com/cloudquery/plugin-sdk/v4/schema"
57
"github.com/stretchr/testify/assert"
6-
"testing"
78
)
89

910
func TestContainsPaidTables(t *testing.T) {
@@ -28,12 +29,22 @@ func TestMakeAllTablesPaid(t *testing.T) {
2829
&schema.Table{Name: "table1", IsPaid: false},
2930
&schema.Table{Name: "table2", IsPaid: false},
3031
&schema.Table{Name: "table3", IsPaid: false},
32+
&schema.Table{Name: "table_with_relations", IsPaid: false, Relations: schema.Tables{
33+
&schema.Table{Name: "relation_table", IsPaid: false},
34+
}},
3135
}
3236

3337
paidTables := MakeAllTablesPaid(noPaidTables)
3438

35-
assert.Equal(t, 3, len(paidTables))
36-
for _, table := range paidTables {
39+
assert.Equal(t, 4, len(paidTables))
40+
assert.Equal(t, 5, len(paidTables.FlattenTables()))
41+
assertAllArePaid(t, paidTables)
42+
}
43+
44+
func assertAllArePaid(t *testing.T, tables schema.Tables) {
45+
t.Helper()
46+
for _, table := range tables {
3747
assert.True(t, table.IsPaid)
48+
assertAllArePaid(t, table.Relations)
3849
}
3950
}

0 commit comments

Comments
 (0)