Skip to content

Commit d4154fb

Browse files
authored
feat(test): Test writing to a child table (#878)
Closes #877
1 parent da9ed4d commit d4154fb

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

internal/memdb/memdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (c *client) overwrite(table *schema.Table, data arrow.Record) {
9595
}
9696

9797
func (c *client) Migrate(_ context.Context, tables schema.Tables) error {
98-
for _, table := range tables {
98+
for _, table := range tables.FlattenTables() {
9999
tableName := table.Name
100100
memTable := c.memoryDB[tableName]
101101
if memTable == nil {

plugins/destination/plugin_testing_overwrite.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Context,
2020
}
2121
tableName := fmt.Sprintf("cq_%s_%d", spec.Name, time.Now().Unix())
2222
table := schema.TestTable(tableName, testSourceOptions...)
23+
parent := schema.TestTable(tableName+"_parent", testSourceOptions...)
24+
parent.Relations = schema.Tables{table}
2325
syncTime := time.Now().UTC().Round(1 * time.Second)
24-
tables := schema.Tables{
25-
table,
26-
}
27-
if err := p.Migrate(ctx, tables); err != nil {
26+
if err := p.Migrate(ctx, schema.Tables{parent}); err != nil {
2827
return fmt.Errorf("failed to migrate tables: %w", err)
2928
}
3029

plugins/destination/plugin_testing_overwrite_delete_stale.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwriteDeleteStale(ctx conte
2222
table := schema.TestTable(tableName, testSourceOptions...)
2323
incTable := schema.TestTable(tableName+"_incremental", testSourceOptions...)
2424
incTable.IsIncremental = true
25+
parent := schema.TestTable(tableName+"_parent", testSourceOptions...)
26+
parent.Relations = schema.Tables{table, incTable}
2527
syncTime := time.Now().UTC().Round(1 * time.Second)
26-
tables := schema.Tables{
27-
table,
28-
incTable,
29-
}
30-
if err := p.Migrate(ctx, tables); err != nil {
28+
if err := p.Migrate(ctx, schema.Tables{parent}); err != nil {
3129
return fmt.Errorf("failed to migrate tables: %w", err)
3230
}
3331

@@ -108,7 +106,7 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwriteDeleteStale(ctx conte
108106
return fmt.Errorf("after overwrite expected first resource to be different. diff: %s", diff)
109107
}
110108

111-
resourcesRead, err = p.readAll(ctx, tables[0], sourceName)
109+
resourcesRead, err = p.readAll(ctx, table, sourceName)
112110
if err != nil {
113111
return fmt.Errorf("failed to read all second time: %w", err)
114112
}
@@ -124,7 +122,7 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwriteDeleteStale(ctx conte
124122

125123
// we expect the incremental table to still have 2 resources, because delete-stale should
126124
// not apply there
127-
resourcesRead, err = p.readAll(ctx, tables[1], sourceName)
125+
resourcesRead, err = p.readAll(ctx, incTable, sourceName)
128126
if err != nil {
129127
return fmt.Errorf("failed to read all from incremental table: %w", err)
130128
}

plugins/destination/plugin_testing_write_append.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ func (s *PluginTestSuite) destinationPluginTestWriteAppend(ctx context.Context,
1919
}
2020
tableName := fmt.Sprintf("cq_%s_%d", spec.Name, time.Now().Unix())
2121
table := schema.TestTable(tableName, testSourceOptions...)
22+
parent := schema.TestTable(tableName+"_parent", testSourceOptions...)
23+
parent.Relations = schema.Tables{table}
2224
syncTime := time.Now().UTC().Round(1 * time.Second)
23-
tables := schema.Tables{
24-
table,
25-
}
26-
if err := p.Migrate(ctx, tables); err != nil {
25+
if err := p.Migrate(ctx, schema.Tables{parent}); err != nil {
2726
return fmt.Errorf("failed to migrate tables: %w", err)
2827
}
2928

@@ -53,7 +52,7 @@ func (s *PluginTestSuite) destinationPluginTestWriteAppend(ctx context.Context,
5352
}
5453
}
5554

56-
resourcesRead, err := p.readAll(ctx, tables[0], sourceName)
55+
resourcesRead, err := p.readAll(ctx, table, sourceName)
5756
if err != nil {
5857
return fmt.Errorf("failed to read all second time: %w", err)
5958
}

0 commit comments

Comments
 (0)