Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fixes converting to TPF by including all attributes in replication_specs #2894

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/testutil/acc/advanced_cluster_schema_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ func getReplicationSpecs(t *testing.T, body *hclsyntax.Body) cty.Value {
assert.Equal(t, name, block.Type, "unexpected block type: %s", block.Type)
vals = append(vals, hcl.GetAttrVal(t, block.Body))
}
return cty.ObjectVal(map[string]cty.Value{
attributeValues := map[string]cty.Value{
name: cty.TupleVal(vals),
})
}
hcl.AddAttributes(t, body, attributeValues)
return cty.ObjectVal(attributeValues)
}
4 changes: 3 additions & 1 deletion internal/testutil/acc/advanced_cluster_schema_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestConvertAdvancedClusterToSchemaV2(t *testing.T) {
cluster_type = "SHARDED"

replication_specs {
zone_name = "zone1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

region_configs {
electable_specs {
disk_size_gb = 10
Expand Down Expand Up @@ -198,7 +199,8 @@ func TestConvertAdvancedClusterToSchemaV2(t *testing.T) {
priority = 6
provider_name = "AZURE"
region_name = "US_EAST_2"
}]
}]
zone_name = "zone1"
}, {
region_configs = [{
analytics_specs = {
Expand Down
13 changes: 9 additions & 4 deletions internal/testutil/hcl/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ func getTF() *tfexec.Terraform {
func GetAttrVal(t *testing.T, body *hclsyntax.Body) cty.Value {
t.Helper()
ret := make(map[string]cty.Value)
AddAttributes(t, body, ret)
for _, block := range body.Blocks {
ret[block.Type] = GetAttrVal(t, block.Body)
}
return cty.ObjectVal(ret)
}

func AddAttributes(t *testing.T, body *hclsyntax.Body, ret map[string]cty.Value) {
t.Helper()
for name, attr := range body.Attributes {
val, diags := attr.Expr.Value(nil)
require.False(t, diags.HasErrors(), "failed to parse attribute %s: %s", name, diags.Error())
ret[name] = val
}
for _, block := range body.Blocks {
ret[block.Type] = GetAttrVal(t, block.Body)
}
return cty.ObjectVal(ret)
}

func PrettyHCL(t *testing.T, content string) string {
Expand Down
Loading