Skip to content

Commit faacca6

Browse files
authored
feat: Add precision options for dest testing (#893)
Needed for mongodb cloudquery/cloudquery#10819
1 parent bc3c251 commit faacca6

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

plugins/destination/plugin_testing.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ func WithTestIgnoreNullsInLists() func(o *PluginTestSuiteRunnerOptions) {
111111
}
112112
}
113113

114+
func WithTestSourceTimePrecision(precision time.Duration) func(o *PluginTestSuiteRunnerOptions) {
115+
return func(o *PluginTestSuiteRunnerOptions) {
116+
o.TimePrecision = precision
117+
}
118+
}
119+
114120
func WithTestSourceSkipLists() func(o *PluginTestSuiteRunnerOptions) {
115121
return func(o *PluginTestSuiteRunnerOptions) {
116122
o.SkipLists = true
@@ -173,7 +179,11 @@ func PluginTestSuiteRunner(t *testing.T, newPlugin NewPluginFunc, destSpec specs
173179
tests: tests,
174180
}
175181

176-
opts := PluginTestSuiteRunnerOptions{}
182+
opts := PluginTestSuiteRunnerOptions{
183+
TestSourceOptions: schema.TestSourceOptions{
184+
TimePrecision: time.Microsecond,
185+
},
186+
}
177187
for _, o := range testOptions {
178188
o(&opts)
179189
}

plugins/destination/plugin_testing_migrate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ func testMigration(ctx context.Context, _ *testing.T, p *Plugin, logger zerolog.
3636
}
3737
syncTime := time.Now().UTC().Round(1 * time.Second)
3838
opts := schema.GenTestDataOptions{
39-
SourceName: sourceName,
40-
SyncTime: syncTime,
41-
MaxRows: 1,
39+
SourceName: sourceName,
40+
SyncTime: syncTime,
41+
MaxRows: 1,
42+
TimePrecision: testOpts.TimePrecision,
4243
}
4344
resource1 := schema.GenTestData(source, opts)[0]
4445
if err := p.writeOne(ctx, sourceSpec, syncTime, resource1); err != nil {

plugins/destination/plugin_testing_overwrite.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Context,
3434
}
3535

3636
opts := schema.GenTestDataOptions{
37-
SourceName: sourceName,
38-
SyncTime: syncTime,
39-
MaxRows: 2,
37+
SourceName: sourceName,
38+
SyncTime: syncTime,
39+
MaxRows: 2,
40+
TimePrecision: testOpts.TimePrecision,
4041
}
4142
resources := schema.GenTestData(table, opts)
4243
if err := p.writeAll(ctx, sourceSpec, syncTime, resources); err != nil {
@@ -72,10 +73,11 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Context,
7273
cqIDInds := resources[0].Schema().FieldIndices(schema.CqIDColumn.Name)
7374
u := resources[0].Column(cqIDInds[0]).(*types.UUIDArray).Value(0)
7475
opts = schema.GenTestDataOptions{
75-
SourceName: sourceName,
76-
SyncTime: secondSyncTime,
77-
MaxRows: 1,
78-
StableUUID: u,
76+
SourceName: sourceName,
77+
SyncTime: secondSyncTime,
78+
MaxRows: 1,
79+
StableUUID: u,
80+
TimePrecision: testOpts.TimePrecision,
7981
}
8082
updatedResource := schema.GenTestData(table, opts)
8183
// write second time

plugins/destination/plugin_testing_overwrite_delete_stale.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwriteDeleteStale(ctx conte
3838
}
3939

4040
opts := schema.GenTestDataOptions{
41-
SourceName: sourceName,
42-
SyncTime: syncTime,
43-
MaxRows: 2,
41+
SourceName: sourceName,
42+
SyncTime: syncTime,
43+
MaxRows: 2,
44+
TimePrecision: testOpts.TimePrecision,
4445
}
4546
resources := schema.GenTestData(table, opts)
4647
incResources := schema.GenTestData(incTable, opts)
@@ -87,10 +88,11 @@ func (*PluginTestSuite) destinationPluginTestWriteOverwriteDeleteStale(ctx conte
8788
cqIDInds := resources[0].Schema().FieldIndices(schema.CqIDColumn.Name)
8889
u := resources[0].Column(cqIDInds[0]).(*types.UUIDArray).Value(0)
8990
opts = schema.GenTestDataOptions{
90-
SourceName: sourceName,
91-
SyncTime: secondSyncTime,
92-
StableUUID: u,
93-
MaxRows: 1,
91+
SourceName: sourceName,
92+
SyncTime: secondSyncTime,
93+
StableUUID: u,
94+
MaxRows: 1,
95+
TimePrecision: testOpts.TimePrecision,
9496
}
9597
updatedResources := schema.GenTestData(table, opts)
9698
updatedIncResources := schema.GenTestData(incTable, opts)

plugins/destination/plugin_testing_write_append.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ func (s *PluginTestSuite) destinationPluginTestWriteAppend(ctx context.Context,
3333
}
3434

3535
opts := schema.GenTestDataOptions{
36-
SourceName: sourceName,
37-
SyncTime: syncTime,
38-
MaxRows: 2,
36+
SourceName: sourceName,
37+
SyncTime: syncTime,
38+
MaxRows: 2,
39+
TimePrecision: testOpts.TimePrecision,
3940
}
4041
record1 := schema.GenTestData(table, opts)
4142
if err := p.writeAll(ctx, specSource, syncTime, record1); err != nil {

schema/testdata.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type TestSourceOptions struct {
2727
SkipDurations bool
2828
SkipTimes bool // time of day types
2929
SkipLargeTypes bool // e.g. large binary, large string
30+
TimePrecision time.Duration
3031
}
3132

3233
// TestSourceColumns returns columns for all Arrow types and composites thereof. TestSourceOptions controls
@@ -257,7 +258,8 @@ type GenTestDataOptions struct {
257258
// StableUUID is the UUID to use for all rows. If set to uuid.Nil, a new UUID will be generated
258259
StableUUID uuid.UUID
259260
// StableTime is the time to use for all rows other than sync time. If set to time.Time{}, a new time will be generated
260-
StableTime time.Time
261+
StableTime time.Time
262+
TimePrecision time.Duration
261263
}
262264

263265
// GenTestData generates a slice of arrow.Records with the given schema and options.
@@ -407,6 +409,8 @@ func getExampleJSON(colName string, dataType arrow.DataType, opts GenTestDataOpt
407409
} else if !opts.StableTime.IsZero() {
408410
t = opts.StableTime
409411
}
412+
t = t.Truncate(opts.TimePrecision)
413+
410414
switch timestampType {
411415
case arrow.FixedWidthTypes.Timestamp_s:
412416
return strconv.FormatInt(t.Unix(), 10)

0 commit comments

Comments
 (0)