Skip to content

Commit

Permalink
[ignore] Addition of recursive sub-templates for removing one child a…
Browse files Browse the repository at this point in the history
…nd all children if they deletable
  • Loading branch information
shrsr committed Jun 20, 2024
1 parent 5b3eaaf commit f16ca88
Show file tree
Hide file tree
Showing 38 changed files with 695 additions and 318 deletions.
134 changes: 107 additions & 27 deletions gen/templates/resource_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ resource "aci_{{$.resourceName}}" "test" {
{{- range $child := $value}}
{
{{- range $child_key, $child_value := $child}}
{{- if ne $child_key "deletable_child"}}
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" " " -}}
{{- template "nestedChildren" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$child_key}} = "{{$child_value}}"
{{- end}}
{{- end}}
Expand Down Expand Up @@ -648,21 +651,23 @@ resource "aci_{{$.resourceName}}" "test" {
{{- end }}
{{- end}}
{{- range $key, $value := $.children}}
{{- if eq (len $value) 1}}
{{- $child := index $value 0}}
{{- if $child.deletable_child}}
{{$key}} = []
{{- end}}
{{- else}}
{{$key}} = [ {{$child := index $value 1 }}
{
{{- range $child_key, $child_value := $child}}
{{$key}} = [
{{- range $index, $child := $value}}
{{- if or (ne $index 0) (and (eq $index 0) (not $child.deletable_child)) }}
{
{{- range $child_key, $child_value := $child}}
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" " " -}}
{{- template "nestedChildrenRemoveOne" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$child_key}} = "{{$child_value}}"
{{- end}}
},
{{- end}}
},
{{- end}}
{{- end}}
]
{{- end}}
{{- end}}
{{- end}}
}
`

Expand All @@ -677,15 +682,23 @@ resource "aci_{{$.resourceName}}" "test" {
{{- end }}
{{- end}}
{{- range $key, $value := $.children}}
{{- if eq (len $value) 1}}
{{- $child := index $value 0}}
{{- if $child.deletable_child}}
{{$key}} = []
{{- end}}
{{- else}}
{{$key}} = []
{{$key}} = [
{{- range $index, $child := $value}}
{{- if not $child.deletable_child }}
{
{{- range $child_key, $child_value := $child}}
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" " " -}}
{{- template "nestedChildrenRemoveAll" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$child_key}} = "{{$child_value}}"
{{- end}}
{{- end}}
{{- end}}
},
{{- end}}
{{- end}}
]
{{- end}}
}
`
{{- end}}
Expand Down Expand Up @@ -765,14 +778,20 @@ resource "aci_{{$.resourceName}}" "test" {
{{- end}}
{{- range $key, $value := $.children}}
{{$key}} = [
{{- if gt (len $value) 1}}
{{$child := index $value 1}}
{{- range $index, $child := $value}}
{{- if or (ne $index 0) (and (eq $index 0) (not $child.deletable_child)) }}
{
{{- range $child_key, $child_value := $child}}
{{$child_key}} = "{{$child_value}}"
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" " " -}}
{{- template "nestedChildrenRemoveOne" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$child_key}} = "{{$child_value}}"
{{- end}}
{{- end}}
},
{{- end}}
{{- end}}
{{- end}}
]
{{- end}}
}
Expand All @@ -784,8 +803,23 @@ resource "aci_{{$.resourceName}}" "test" {
{{$key}} = "{{$value}}"
{{- end}}
{{- range $key, $value := $.children}}
{{$key}} = []
{{- end}}
{{$key}} = [
{{- range $index, $child := $value}}
{{- if not $child.deletable_child }}
{
{{- range $child_key, $child_value := $child}}
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" " " -}}
{{- template "nestedChildrenRemoveAll" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$child_key}} = "{{$child_value}}"
{{- end}}
{{- end}}
},
{{- end}}
{{- end}}
]
{{- end}}
}
`

Expand All @@ -812,4 +846,50 @@ resource "aci_{{$.resourceName}}" "test" {
{{- end}}
{{$indent}}]
{{- end}}
{{- end}}

{{/* A sub template for including nested children by removing only one child that is deletable. */}}
{{- define "nestedChildrenRemoveOne" -}}
{{- $indent := .TemplateProperties.Indent -}}
{{- range $key, $value := .childValue}}
{{$indent}}{{$key}} = [
{{- range $index, $child := $value}}
{{- if or (ne $index 0) (and (eq $index 0) (not $child.deletable_child)) }}
{{$indent}}{
{{- range $child_key, $child_value := $child}}
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" (print $indent " ") -}}
{{- template "nestedChildrenRemoveOne" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$indent}}{{$child_key}} = "{{$child_value}}"
{{- end}}
{{- end}}
{{$indent}}},
{{- end}}
{{- end}}
{{$indent}}]
{{- end}}
{{- end}}

{{/* A sub template for including nested children by removing all deletable children. */}}
{{- define "nestedChildrenRemoveAll" -}}
{{- $indent := .TemplateProperties.Indent -}}
{{- range $key, $value := .childValue}}
{{$indent}}{{$key}} = [
{{- range $index, $child := $value}}
{{- if not $child.deletable_child }}
{{$indent}}{
{{- range $child_key, $child_value := $child}}
{{- if eq $child_key "children"}}
{{- $newCtx := addToChild $child_value "Indent" (print $indent " ") -}}
{{- template "nestedChildrenRemoveAll" $newCtx }}
{{- else if ne $child_key "deletable_child"}}
{{$indent}}{{$child_key}} = "{{$child_value}}"
{{- end}}
{{- end}}
{{$indent}}},
{{- end}}
{{- end}}
{{$indent}}]
{{- end}}
{{- end}}
13 changes: 12 additions & 1 deletion gen/templates/testvars.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,20 @@ targets:
{{- $enteredPropertiesZone1 := false }}
{{ $indent }}- {{ range .Properties}}{{- if $enteredPropertiesZone1 }}{{ $indent }}{{- else}}{{- $enteredPropertiesZone1 = true }}{{- end}}{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}_1"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}
{{ end}}
{{- if $child_deletable -}}
{{ $indent }}deletable_child: true
{{- else -}}
{{ $indent }}deletable_child: false
{{ end}}
{{- $enteredPropertiesZone2 := false }}
{{ $indent }}- {{ range .Properties}}{{- if $enteredPropertiesZone2 }}{{ $indent }}{{- else}}{{- $enteredPropertiesZone2 = true }}{{- end}}{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{$length := len .ValidValues}}{{if ge $length 2}}"{{ index .ValidValues 1 }}"{{else if not .IsNaming}}"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}_2"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 1 $.Definitions}}"{{- end}}
{{ end}}{{- end}}
{{ end}}
{{- if $child_deletable -}}
{{ $indent }}deletable_child: true
{{- else -}}
{{ $indent }}deletable_child: false
{{ end}}
{{- end}}
{{- $enteredGrandChildZone := false }}
{{- range .Children}}
{{- if not $enteredGrandChildZone }}
Expand Down
32 changes: 16 additions & 16 deletions gen/testvars/commPol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ children:
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
key_ring:
- annotation: "annotation_1"
tn_pki_key_ring_name: "tn_pki_key_ring_name_1"
Expand All @@ -82,45 +82,45 @@ children:
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true



8 changes: 4 additions & 4 deletions gen/testvars/fvEpIpTag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ children:
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
parents:
- class_name: "fvTenant"
parent_dependency: ""
Expand Down
8 changes: 4 additions & 4 deletions gen/testvars/fvEpMacTag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ children:
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
parents:
- class_name: "fvTenant"
parent_dependency: ""
Expand Down
20 changes: 10 additions & 10 deletions gen/testvars/fvFBRGroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,42 @@ children:
name: "name_1"
name_alias: "name_alias_1"
fallback_member: "2.2.2.2"

deletable_child: true
- annotation: "annotation_2"
description: "description_2"
name: "name_2"
name_alias: "name_alias_2"
fallback_member: "2.2.2.3"

deletable_child: true
children:
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
annotations:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
tags:
- key: "key_0"
value: "value_1"

deletable_child: true
- key: "key_1"
value: "value_2"

deletable_child: true
parents:
- class_name: "fvCtx"
parent_dependency: "fvTenant"
Expand Down
Loading

0 comments on commit f16ca88

Please sign in to comment.