Skip to content

Commit

Permalink
source-redshift-batch: Add TestFeatureFlagUseSchemaInference
Browse files Browse the repository at this point in the history
Just a simple test case to make sure the `use_schema_inference`
feature flag does what it was intended to.
  • Loading branch information
willdonnelly committed Dec 6, 2024
1 parent caa3432 commit 82315d3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Binding 0:
{
"resource_config_json": {
"name": "test_feature_flag_use_schema_inference_77244729",
"template": "{{if .CursorFields -}}\n {{- if .IsFirstQuery -}}\n SELECT * FROM \"test\".\"feature_flag_use_schema_inference_77244729\"\n {{- else -}}\n SELECT * FROM \"test\".\"feature_flag_use_schema_inference_77244729\"\n\t{{- range $i, $k := $.CursorFields -}}\n\t {{- if eq $i 0}} WHERE ({{else}}) OR ({{end -}}\n {{- range $j, $n := $.CursorFields -}}\n\t\t{{- if lt $j $i -}}\n\t\t {{$n}} = ${{add $j 1}} AND {{end -}}\n\t {{- end -}}\n\t {{$k}} \u003e ${{add $i 1}}\n\t{{- end -}}\n\t) \n {{- end}} ORDER BY {{range $i, $k := $.CursorFields}}{{if gt $i 0}}, {{end}}{{$k}}{{end -}};\n{{- else -}}\n SELECT * FROM \"test\".\"feature_flag_use_schema_inference_77244729\";\n{{- end}}\n"
},
"resource_path": [
"test_feature_flag_use_schema_inference_77244729"
],
"collection": {
"name": "acmeCo/test/test_feature_flag_use_schema_inference_77244729",
"read_schema_json": {
"type": "object",
"required": [
"_meta",
"id"
],
"properties": {
"_meta": {
"$schema": "http://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/estuary/connectors/source-redshift-batch/document-metadata",
"properties": {
"polled": {
"type": "string",
"format": "date-time",
"title": "Polled Timestamp",
"description": "The time at which the update query which produced this document as executed."
},
"index": {
"type": "integer",
"title": "Result Index",
"description": "The index of this document within the query execution which produced it."
}
},
"type": "object",
"required": [
"polled",
"index"
]
},
"data": {
"type": [
"string",
"null"
]
},
"id": {
"type": "integer"
}
},
"x-infer-schema": true
},
"key": [
"/id"
],
"projections": null
},
"state_key": "test_feature_flag_use_schema_inference_77244729"
}

18 changes: 18 additions & 0 deletions source-redshift-batch/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,21 @@ func snapshotBindings(t testing.TB, bindings []*pf.CaptureSpec_Binding) {
}
cupaloy.SnapshotT(t, summary.String())
}

func TestFeatureFlagUseSchemaInference(t *testing.T) {
var ctx, cs = context.Background(), testCaptureSpec(t)
var control = testControlClient(ctx, t)
var uniqueID = "77244729"
var tableName = fmt.Sprintf("test.feature_flag_use_schema_inference_%s", uniqueID)

// Includes some extra junk to make sure the parsing helper logic is doing its job as intended
cs.EndpointSpec.(*Config).Advanced.FeatureFlags = "this_flag_does_not_exist,use_schema_inference,,,,no_this_flag_also_does_not_exist"

executeControlQuery(ctx, t, control, fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName))
t.Cleanup(func() { executeControlQuery(ctx, t, control, fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)) })
executeControlQuery(ctx, t, control, fmt.Sprintf("CREATE TABLE %s(id INTEGER PRIMARY KEY, data TEXT)", tableName))

// Discover the table and verify discovery snapshot
cs.Bindings = discoverStreams(ctx, t, cs, regexp.MustCompile(uniqueID))
t.Run("Discovery", func(t *testing.T) { snapshotBindings(t, cs.Bindings) })
}

0 comments on commit 82315d3

Please sign in to comment.