Skip to content

Commit 95ab353

Browse files
authored
fix(testing): Fix bug in testing missed due to reference to resource being re-used in memdb (#567)
1 parent a0d4671 commit 95ab353

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

plugins/destination/plugin_testing.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,20 @@ func (s *PluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Contex
7777

7878
if diff := resources[1].Data.Diff(resourcesRead[1]); diff != "" {
7979
return fmt.Errorf("expected second resource diff: %s", diff)
80-
// return fmt.Errorf("expected second resource to be:\n%v\ngot:\n%v", resource.Data, resourcesRead[1])
8180
}
8281

8382
secondSyncTime := syncTime.Add(time.Second).UTC()
84-
_ = resources[0].Data[1].Set(secondSyncTime)
85-
sortResources(table, resources)
83+
84+
// copy first resource but update the sync time
85+
updatedResource := schema.DestinationResource{
86+
TableName: table.Name,
87+
Data: make(schema.CQTypes, len(resources[0].Data)),
88+
}
89+
copy(updatedResource.Data, resources[0].Data)
90+
_ = updatedResource.Data[1].Set(secondSyncTime)
8691

8792
// write second time
88-
if err := p.writeOne(ctx, tables, sourceName, secondSyncTime, resources[0]); err != nil {
93+
if err := p.writeOne(ctx, tables, sourceName, secondSyncTime, updatedResource); err != nil {
8994
return fmt.Errorf("failed to write one second time: %w", err)
9095
}
9196

@@ -99,11 +104,11 @@ func (s *PluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Contex
99104
return fmt.Errorf("after overwrite expected 2 resources, got %d", len(resourcesRead))
100105
}
101106

102-
if diff := resources[0].Data.Diff(resourcesRead[0]); diff != "" {
107+
if diff := resources[1].Data.Diff(resourcesRead[0]); diff != "" {
103108
return fmt.Errorf("after overwrite expected first resource diff: %s", diff)
104109
}
105110

106-
if diff := resources[1].Data.Diff(resourcesRead[1]); diff != "" {
111+
if diff := updatedResource.Data.Diff(resourcesRead[1]); diff != "" {
107112
return fmt.Errorf("after overwrite expected second resource diff: %s", diff)
108113
}
109114

@@ -123,8 +128,8 @@ func (s *PluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Contex
123128
return fmt.Errorf("expected 1 resource after delete stale, got %d", len(resourcesRead))
124129
}
125130

126-
// we expect the only resource returned to match the second resource we wrote
127-
if diff := resources[1].Data.Diff(resourcesRead[0]); diff != "" {
131+
// we expect the only resource returned to match the updated resource we wrote
132+
if diff := updatedResource.Data.Diff(resourcesRead[0]); diff != "" {
128133
return fmt.Errorf("after delete stale expected resource diff: %s", diff)
129134
}
130135

@@ -254,8 +259,8 @@ func sortResources(table *schema.Table, resources []schema.DestinationResource)
254259
syncTimeIndex := table.Columns.Index(schema.CqSyncTimeColumn.Name)
255260
sort.Slice(resources, func(i, j int) bool {
256261
// sort by sync time, then UUID
257-
if resources[i].Data[syncTimeIndex].String() != resources[j].Data[syncTimeIndex].String() {
258-
return resources[i].Data[syncTimeIndex].String() < resources[j].Data[syncTimeIndex].String()
262+
if !resources[i].Data[syncTimeIndex].Equal(resources[j].Data[syncTimeIndex]) {
263+
return resources[i].Data[syncTimeIndex].Get().(time.Time).Before(resources[j].Data[syncTimeIndex].Get().(time.Time))
259264
}
260265
return resources[i].Data[cqIDIndex].String() < resources[j].Data[cqIDIndex].String()
261266
})
@@ -266,8 +271,8 @@ func sortCQTypes(table *schema.Table, resources []schema.CQTypes) {
266271
syncTimeIndex := table.Columns.Index(schema.CqSyncTimeColumn.Name)
267272
sort.Slice(resources, func(i, j int) bool {
268273
// sort by sync time, then UUID
269-
if resources[i][syncTimeIndex].String() != resources[j][syncTimeIndex].String() {
270-
return resources[i][syncTimeIndex].String() < resources[j][syncTimeIndex].String()
274+
if !resources[i][syncTimeIndex].Equal(resources[j][syncTimeIndex]) {
275+
return resources[i][syncTimeIndex].Get().(time.Time).Before(resources[j][syncTimeIndex].Get().(time.Time))
271276
}
272277
return resources[i][cqIDIndex].String() < resources[j][cqIDIndex].String()
273278
})

0 commit comments

Comments
 (0)