Skip to content

Commit

Permalink
converter for advanced_configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Nov 29, 2024
1 parent 063fc3c commit 31f39cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/testutil/acc/tpf_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func ConvertAdvancedClusterToTPF(t *testing.T, def string) string {
continue
}
writeBody := resource.Body()
convertAttrs(t, "labels", writeBody, getAttrVal)
convertAttrs(t, "tags", writeBody, getAttrVal)
convertAttrs(t, "replication_specs", writeBody, getReplicationSpecs)
convertAttrs(t, "labels", writeBody, true, getAttrVal)
convertAttrs(t, "tags", writeBody, true, getAttrVal)
convertAttrs(t, "replication_specs", writeBody, true, getReplicationSpecs)
convertAttrs(t, "advanced_configuration", writeBody, false, getAttrVal)
}
content := parse.Bytes()
return string(content)
Expand All @@ -39,7 +40,7 @@ func AssertEqualHCL(t *testing.T, expected, actual string, msgAndArgs ...interfa
assert.Equal(t, canonicalHCL(t, expected), canonicalHCL(t, actual), msgAndArgs...)
}

func convertAttrs(t *testing.T, name string, writeBody *hclwrite.Body, getOneAttr func(*testing.T, *hclsyntax.Body) cty.Value) {
func convertAttrs(t *testing.T, name string, writeBody *hclwrite.Body, isList bool, getOneAttr func(*testing.T, *hclsyntax.Body) cty.Value) {
t.Helper()
var vals []cty.Value
for {
Expand All @@ -50,8 +51,14 @@ func convertAttrs(t *testing.T, name string, writeBody *hclwrite.Body, getOneAtt
vals = append(vals, getOneAttr(t, getBlockBody(t, match)))
writeBody.RemoveBlock(match) // TODO: RemoveBlock doesn't remove newline just after the block so an extra line is added
}
if len(vals) > 0 {
if len(vals) == 0 {
return
}
if isList {
writeBody.SetAttributeValue(name, cty.TupleVal(vals))
} else {
assert.Len(t, vals, 1, "can be only one of %s", name)
writeBody.SetAttributeValue(name, vals[0])
}
}

Expand Down
24 changes: 24 additions & 0 deletions internal/testutil/acc/tpf_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ func TestConvertAdvancedClusterToTPF(t *testing.T) {
key = "Key Label 3"
value = "Value Label 3"
}
advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
oplog_size_mb = 1000
sample_size_bi_connector = 110
sample_refresh_interval_bi_connector = 310
transaction_lifetime_limit_seconds = 300
change_stream_options_pre_and_post_images_expire_after_seconds = 100
}
}
`
// expected has the attributes sorted alphabetically to match the output of ConvertAdvancedClusterToTPF
Expand All @@ -97,6 +109,7 @@ func TestConvertAdvancedClusterToTPF(t *testing.T) {
labels = [{
key = "Key Label 1"
Expand Down Expand Up @@ -156,6 +169,17 @@ func TestConvertAdvancedClusterToTPF(t *testing.T) {
region_name = "EU_WEST_1"
}]
}]
advanced_configuration = {
change_stream_options_pre_and_post_images_expire_after_seconds = 100
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
oplog_size_mb = 1000
sample_refresh_interval_bi_connector = 310
sample_size_bi_connector = 110
transaction_lifetime_limit_seconds = 300
}
}
`
)
Expand Down

0 comments on commit 31f39cb

Please sign in to comment.