Skip to content

Commit

Permalink
[ignore] Fixed generator to handle lists of values for properties ign…
Browse files Browse the repository at this point in the history
…ored in tests.
  • Loading branch information
samiib committed Nov 15, 2024
1 parent 8b75d29 commit b978a70
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/resources/certificate_authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ hvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl
KU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=
-----END CERTIFICATE-----
EOT
certificate_usage = test_value
certificate_usage = ["WebSvcOrAuth"]
description = "description_1"
name = "test_name"
name_alias = "name_alias_1"
Expand Down Expand Up @@ -145,7 +145,7 @@ hvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl
KU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=
-----END CERTIFICATE-----
EOT
certificate_usage = test_value
certificate_usage = ["WebSvcOrAuth"]
description = "description_1"
name = "test_name"
name_alias = "name_alias_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl
KU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=
-----END CERTIFICATE-----
EOT
certificate_usage = test_value
certificate_usage = ["WebSvcOrAuth"]
description = "description_1"
name = "test_name"
name_alias = "name_alias_1"
Expand Down Expand Up @@ -57,7 +57,7 @@ hvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl
KU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=
-----END CERTIFICATE-----
EOT
certificate_usage = test_value
certificate_usage = ["WebSvcOrAuth"]
description = "description_1"
name = "test_name"
name_alias = "name_alias_1"
Expand Down
4 changes: 1 addition & 3 deletions gen/definitions/properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ pkiTP:
overwrites:
cert_usage: "certificate_usage"
cert_chain: "certificate_chain"
ignores:
- "certUsage"
resource_required:
- "certChain"
ignore_properties_in_test:
certUsage: ""
certUsage: ["WebSvcOrAuth"]
documentation:
certUsage: "The certificate usage of the Certificate Authority object."
test_values:
Expand Down
19 changes: 16 additions & 3 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func LookupTestValue(classPkgName, originalPropertyName string, testVars map[str
lookupValue = fmt.Sprintf(`"%s"`, val)
}
case []interface{}:
lookupValue = val
lookupValue = formatSlice(val)
}
}

Expand All @@ -468,7 +468,7 @@ func LookupTestValue(classPkgName, originalPropertyName string, testVars map[str
lookupValue = fmt.Sprintf(`"%s"`, val)
}
case []interface{}:
lookupValue = val
lookupValue = formatSlice(val)
}
}
}
Expand Down Expand Up @@ -1805,7 +1805,12 @@ func ignoreTestProperty(propertyName, classPkgName string, definitions Definitio
if key.(string) == "ignore_properties_in_test" {
for k, v := range value.(map[interface{}]interface{}) {
if k.(string) == propertyName {
return true, v.(string)
switch val := v.(type) {
case []interface{}:
return true, formatSlice(val)
default:
return true, fmt.Sprintf(`"%s"`, val)
}
}
}
}
Expand All @@ -1815,6 +1820,14 @@ func ignoreTestProperty(propertyName, classPkgName string, definitions Definitio
return false, ""
}

func formatSlice(slice []interface{}) string {
formattedSlice := make([]string, len(slice))
for i, v := range slice {
formattedSlice[i] = fmt.Sprintf("\"%v\"", v)
}
return fmt.Sprintf("[%v]", strings.Join(formattedSlice, ", "))
}

func updateVersionMismatched(model *Model, classVersion, propertyVersion, propertyName string) {
classVersionResult := providerFunctions.ParseVersion(classVersion)
propertyVersionResult := providerFunctions.ParseVersion(propertyVersion)
Expand Down
16 changes: 8 additions & 8 deletions gen/templates/resource_example_all_attributes.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit
{{- end}}
{{- end}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
{{- else if eq .ValueType "bitmask"}}{{ $bitmaskTestValue := lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = [{{range $index, $value := $bitmaskTestValue}}{{if lt $index (subtract (len $bitmaskTestValue) 1)}}"{{$value}}",{{else}}"{{$value}}"{{end}}{{end}}]
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}
{{- end}}{{- end}}{{- end}}
Expand All @@ -35,7 +33,7 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit
{{- break}}
{{- end}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupChildTestValue .PkgName $ChildResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}{{ end}}{{- end}}
}
Expand All @@ -49,7 +47,7 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit
{{- break}}
{{- end}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupChildTestValue .PkgName $ChildResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}{{ end}}{{- end}}
}
Expand All @@ -69,7 +67,7 @@ resource "aci_{{$.ResourceName}}" "full_example" {
{{- else if eq .SnakeCaseName "t_dn" }}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties | replace ".test_0.id" ".example.id"}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}
{{- end}}{{- end}}{{- end}}
Expand All @@ -81,7 +79,7 @@ resource "aci_{{$.ResourceName}}" "full_example" {
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeVale := getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 true | replace "test_0" "example_2" }}
target_dn = {{if containsString $attributeVale "."}}{{$attributeVale}}{{else}}"{{$attributeVale}}"{{end}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupChildTestValue .PkgName $ChildResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}{{ end}}{{- end}}
}
Expand All @@ -92,7 +90,7 @@ resource "aci_{{$.ResourceName}}" "full_example" {
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeVale := getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 true | replace "test_0" "example_2" }}
target_dn = {{if containsString $attributeVale "."}}{{$attributeVale}}{{else}}"{{$attributeVale}}"{{end}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupChildTestValue .PkgName $ChildResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}{{ end}}{{- end}}
}
Expand All @@ -115,6 +113,8 @@ resource "aci_{{$topContext.ResourceName}}" {{- if ne $formatValue.ContainedBy "
{{- range $topContext.Properties }}
{{- if ne .NamedPropertyClass ""}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name
{{- else if .IgnoreInTest }}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{.IgnoreInTestExampleValue}}
{{- else}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}
{{- end }}
Expand Down

0 comments on commit b978a70

Please sign in to comment.