Skip to content

Commit

Permalink
chore: Fixes converting to TPF by including all attributes in replica…
Browse files Browse the repository at this point in the history
…tion_specs (#2894)
  • Loading branch information
EspenAlbert authored Dec 16, 2024
1 parent f379847 commit 47633ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
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 @@ -146,7 +146,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"
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

0 comments on commit 47633ce

Please sign in to comment.