Skip to content

Commit c6104a3

Browse files
committed
test: add test using range in template
1 parent 570cc39 commit c6104a3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

controllers/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ spec:
173173
name: default
174174
`
175175

176-
var _ = Describe("Common functions", func() {
176+
var _ = Describe("Attached policies and value precedence", func() {
177177

178178
const (
179179
timeout = time.Second * 10

controllers/gateway_controller_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ kind: GatewayClassBlueprint
8181
metadata:
8282
name: default-gateway-class
8383
spec:
84+
values:
85+
default:
86+
configmap2SuffixData:
87+
- one
88+
- two
89+
- three
8490
gatewayTemplate:
8591
status:
8692
template: |
@@ -109,14 +115,25 @@ spec:
109115
data:
110116
valueToRead1: Hello
111117
valueToRead2: World
112-
configMapTestIntermediate: |
118+
configMapTestIntermediate1: |
113119
apiVersion: v1
114120
kind: ConfigMap
115121
metadata:
116-
name: intermediate-configmap
122+
name: intermediate1-configmap
117123
namespace: {{ .Gateway.metadata.namespace }}
118124
data:
119125
valueIntermediate: {{ (index .Resources.configMapTestSource 0).data.valueToRead1 }}
126+
configMapTestIntermediate2: |
127+
{{ range .Values.configmap2SuffixData }}
128+
apiVersion: v1
129+
kind: ConfigMap
130+
metadata:
131+
name: intermediate2-configmap-{{ . }}
132+
namespace: {{ $.Gateway.metadata.namespace }}
133+
data:
134+
valueIntermediate: {{ (index $.Resources.configMapTestSource 0).data.valueToRead1 }}-{{ . }}
135+
---
136+
{{ end }}
120137
# Use references to multiple resources coupled with template pipeline and functions
121138
configMapTestDestination: |
122139
apiVersion: v1
@@ -125,7 +142,8 @@ spec:
125142
name: dst-configmap
126143
namespace: {{ .Gateway.metadata.namespace }}
127144
data:
128-
valueRead: {{ printf "%s, %s" (index .Resources.configMapTestIntermediate 0).data.valueIntermediate (index .Resources.configMapTestSource 0).data.valueToRead2 | upper }}
145+
valueRead: {{ printf "%s, %s" (index .Resources.configMapTestIntermediate1 0).data.valueIntermediate (index .Resources.configMapTestSource 0).data.valueToRead2 | upper }}
146+
valueRead2: {{ printf "Testing, one two %s" (index .Resources.configMapTestIntermediate2 2).data.valueIntermediate | upper }}
129147
httpRouteTemplate:
130148
resourceTemplates:
131149
shadowHttproute: |
@@ -270,6 +288,7 @@ var _ = Describe("Gateway controller", func() {
270288

271289
By("Setting the content of the destination configmap")
272290
Expect(cm.Data["valueRead"]).To(Equal("HELLO, WORLD"))
291+
Expect(cm.Data["valueRead2"]).To(Equal("TESTING, ONE TWO HELLO-THREE"))
273292
})
274293
})
275294
})

0 commit comments

Comments
 (0)