Skip to content

Commit

Permalink
added thorough unit tests for gateway-resources-configmap.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahalsmiller committed Feb 9, 2024
1 parent c0aaaca commit 4a0902d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 20 deletions.
13 changes: 8 additions & 5 deletions charts/consul/templates/gateway-resources-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ data:
release: {{ .Release.Name }}
component: api-gateway
{{- if .Values.connectInject.apiGateway.managedGatewayClass.copyAnnotations }}
{{- if .Values.connectInject.apiGateway.managedGatewayClass.copyAnnotations.service }}
annotations:
service: {{ .Values.connectInject.apiGateway.managedGatewayClass.copyAnnotations.service }}
service:
{{ fromYamlArray .Values.connectInject.apiGateway.managedGatewayClass.copyAnnotations.service.annotations | toYaml }}
{{- end}}
{{- end}}
deployment:
{{- if .Values.connectInject.apiGateway.managedGatewayClass.nodeSelector }}
nodeSelector:
{{ fromYamlArray .Values.connectInject.apiGateway.managedGatewayClass.nodeSelector | toJson }}
{{ fromYamlArray .Values.connectInject.apiGateway.managedGatewayClass.nodeSelector | toYaml }}
{{- end }}
initContainer:
{{- if .Values.connectInject.apiGateway.managedGatewayClass.mapPrivilegedContainerPorts }}
Expand All @@ -145,18 +148,18 @@ data:
max: {{ .Values.connectInject.apiGateway.managedGatewayClass.deployment.maxInstances }}
{{- if .Values.connectInject.apiGateway.managedGatewayClass.tolerations }}
tolerations:
{{ fromYamlArray .Values.connectInject.apiGateway.managedGatewayClass.tolerations | toJson }}
{{ fromYamlArray .Values.connectInject.apiGateway.managedGatewayClass.tolerations | toYaml }}
{{- end }}
{{- if .Values.connectInject.apiGateway.managedGatewayClass.service }}
service:
annotations:
set: {{ toJson .Values.connectInject.apiGateway.managedGatewayClass.service.annotations }}
set: {{ toYaml .Values.connectInject.apiGateway.managedGatewayClass.service.annotations }}
{{- end }}
type: {{ .Values.connectInject.apiGateway.managedGatewayClass.serviceType }}
{{- if .Values.connectInject.apiGateway.managedGatewayClass.serviceAccount }}
serviceAccount:
annotations:
set: {{ toJson .Values.connectInject.apiGateway.managedGatewayClass.serviceAccount.annotations }}
set: {{ toYaml .Values.connectInject.apiGateway.managedGatewayClass.serviceAccount.annotations }}
{{- end }}
{{- end }}
{{- if .Values.meshGateway.enabled }}
Expand Down
83 changes: 68 additions & 15 deletions charts/consul/test/unit/gateway-resources-configmap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -378,41 +378,94 @@ target=templates/gateway-resources-configmap.yaml
--set 'global.experiments[0]=resource-apis' \
--set 'ui.enabled=false' \
--set 'global.logLevel=error' \
--set 'connectInject.apiGateway.managedGatewayClass.deployment.nodeSelector=2' \
--set 'connectInject.apiGateway.managedGatewayClass.nodeSelector=- key: value' \
. | tee /dev/stderr |
yq -r '.data["config.yaml"]' | yq -r '.gatewayClassConfigs[0].spec.deployment' | tee /dev/stderr)
local actual=$(echo "$config" | yq -r '.replicas.default')
[ "${actual}" = '2' ]
local actual=$(echo "$config" | yq -r '.nodeSelector')
[ "${actual}" = '- key: value' ]
}
local actual=$(echo "$config" | yq -r '.replicas.min')
[ "${actual}" = '1' ]
@test "gateway-resources/ConfigMap: API Gateway nodeSelector default {
cd `chart_dir`
local config=$(helm template \
-s $target \
--set 'global.experiments[0]=resource-apis' \
--set 'ui.enabled=false' \
--set 'global.logLevel=error' \
. | tee /dev/stderr |
yq -r '.data["config.yaml"]' | yq -r '.gatewayClassConfigs[0].spec.deployment' | tee /dev/stderr)

local actual=$(echo "$config" | yq -r '.replicas.max')
[ "${actual}" = '3' ]
local actual=$(echo "$config" | yq -r '.nodeSelector')
[ "${actual}" = 'null' ]
}

@test "gateway-resources/ConfigMap: API Gateway deploymentConfig default {
#--------------------------------------------------------------------
# API Gateway Tests tolerations

@test "gateway-resources/ConfigMap: API Gateway tolerations overrides default {
cd `chart_dir`
local config=$(helm template \
-s $target \
--set 'global.experiments[0]=resource-apis' \
--set 'ui.enabled=false' \
--set 'global.logLevel=error' \
--set 'connectInject.apiGateway.managedGatewayClass.tolerations=- key: value' \
. | tee /dev/stderr |
yq -r '.data["config.yaml"]' | yq -r '.gatewayClassConfigs[0].spec.deployment' | tee /dev/stderr)
local actual=$(echo "$config" | yq -r '.replicas.default')
[ "${actual}" = '1' ]
local actual=$(echo "$config" | yq -r '.tolerations')
[ "${actual}" = '- key: value' ]
}
local actual=$(echo "$config" | yq -r '.replicas.min')
[ "${actual}" = '1' ]
@test "gateway-resources/ConfigMap: API Gateway tolerations default {
cd `chart_dir`
local config=$(helm template \
-s $target \
--set 'global.experiments[0]=resource-apis' \
--set 'ui.enabled=false' \
--set 'global.logLevel=error' \
. | tee /dev/stderr |
yq -r '.data["config.yaml"]' | yq -r '.gatewayClassConfigs[0].spec.deployment' | tee /dev/stderr)

local actual=$(echo "$config" | yq -r '.replicas.max')
[ "${actual}" = '1' ]
local actual=$(echo "$config" | yq -r '.nodeSelector')
[ "${actual}" = 'null' ]
}


#--------------------------------------------------------------------
# API Gateway Tests copyAnnotations

@test "gateway-resources/ConfigMap: API Gateway copyAnnotations overrides default {
cd `chart_dir`
local config=$(helm template \
-s $target \
--set 'global.experiments[0]=resource-apis' \
--set 'ui.enabled=false' \
--set 'global.logLevel=error' \
--set 'connectInject.apiGateway.managedGatewayClass.copyAnnotations.service.annotations=- annotation.name' \
. | tee /dev/stderr |
yq -r '.data["config.yaml"]' | yq -r '.gatewayClassConfigs[0].spec.annotations' | tee /dev/stderr)
local actual=$(echo "$config" | yq -r '.service')
echo "${actual}"
[ "${actual}" = '- annotation.name' ]
}
@test "gateway-resources/ConfigMap: API Gateway copyAnnotations default {
cd `chart_dir`
local config=$(helm template \
-s $target \
--set 'global.experiments[0]=resource-apis' \
--set 'ui.enabled=false' \
--set 'global.logLevel=error' \
. | tee /dev/stderr |
yq -r '.data["config.yaml"]' | yq -r '.gatewayClassConfigs[0].spec.annotations' | tee /dev/stderr)

local actual=$(echo "$config" | yq -r '.service')
[ "${actual}" = 'null' ]
}


#--------------------------------------------------------------------
# TODO openShiftSSCName, tolerations, nodeSelector
# TODO openShiftSSCName

0 comments on commit 4a0902d

Please sign in to comment.