add unit tests that use helm template
This commit is contained in:
parent
d2558a0be3
commit
83fc9d981c
7 changed files with 64 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
# StatefulSet to run the actual Consul server cluster.
|
# StatefulSet to run the actual Consul server cluster.
|
||||||
{{- if (default .Values.server.enabled .Values.global.enabled) }}
|
{{- if (or (and (ne (.Values.server.enabled | toString) "-") .Values.server.enabled) (and (eq (.Values.server.enabled | toString) "-") .Values.global.enabled)) }}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# This Dockerfile installs all the dependencies necessary to run the
|
# This Dockerfile installs all the dependencies necessary to run the unit and
|
||||||
# acceptance tests. This image also contains gcloud so you can run tests
|
# acceptance tests. This image also contains gcloud so you can run tests
|
||||||
# against a GKE cluster easily.
|
# against a GKE cluster easily.
|
||||||
#
|
#
|
||||||
|
@ -19,9 +19,13 @@ RUN apk update && apk add --no-cache --virtual .build-deps \
|
||||||
bash \
|
bash \
|
||||||
openssl \
|
openssl \
|
||||||
python \
|
python \
|
||||||
|
py-pip \
|
||||||
git \
|
git \
|
||||||
jq
|
jq
|
||||||
|
|
||||||
|
# yq
|
||||||
|
RUN pip install yq
|
||||||
|
|
||||||
# gcloud
|
# gcloud
|
||||||
RUN curl -OL https://dl.google.com/dl/cloudsdk/channels/rapid/install_google_cloud_sdk.bash && \
|
RUN curl -OL https://dl.google.com/dl/cloudsdk/channels/rapid/install_google_cloud_sdk.bash && \
|
||||||
bash install_google_cloud_sdk.bash --disable-prompts --install-dir='/root/' && \
|
bash install_google_cloud_sdk.bash --disable-prompts --install-dir='/root/' && \
|
||||||
|
|
4
test/unit/_helpers.bash
Normal file
4
test/unit/_helpers.bash
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# chart_dir returns the directory for the chart
|
||||||
|
chart_dir() {
|
||||||
|
echo ${BATS_TEST_DIRNAME}/../..
|
||||||
|
}
|
53
test/unit/server.bats
Executable file
53
test/unit/server.bats
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load _helpers
|
||||||
|
|
||||||
|
@test "server/ConfigMap: enabled by default" {
|
||||||
|
cd `chart_dir`
|
||||||
|
local actual=$(helm template \
|
||||||
|
-x templates/server-config-configmap.yaml \
|
||||||
|
. | tee /dev/stderr |
|
||||||
|
yq 'length > 0' | tee /dev/stderr)
|
||||||
|
[ "${actual}" = "true" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "server/ConfigMap: enable with global.enabled false" {
|
||||||
|
cd `chart_dir`
|
||||||
|
local actual=$(helm template \
|
||||||
|
-x templates/server-config-configmap.yaml \
|
||||||
|
--set 'global.enabled=false' \
|
||||||
|
--set 'server.enabled=true' \
|
||||||
|
. | tee /dev/stderr |
|
||||||
|
yq 'length > 0' | tee /dev/stderr)
|
||||||
|
[ "${actual}" = "true" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "server/ConfigMap: disable with server.enabled" {
|
||||||
|
cd `chart_dir`
|
||||||
|
local actual=$(helm template \
|
||||||
|
-x templates/server-config-configmap.yaml \
|
||||||
|
--set 'server.enabled=false' \
|
||||||
|
. | tee /dev/stderr |
|
||||||
|
yq 'length > 0' | tee /dev/stderr)
|
||||||
|
[ "${actual}" = "false" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "server/ConfigMap: disable with global.enabled" {
|
||||||
|
cd `chart_dir`
|
||||||
|
local actual=$(helm template \
|
||||||
|
-x templates/server-config-configmap.yaml \
|
||||||
|
--set 'global.enabled=false' \
|
||||||
|
. | tee /dev/stderr |
|
||||||
|
yq 'length > 0' | tee /dev/stderr)
|
||||||
|
[ "${actual}" = "false" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "server/ConfigMap: extraConfig is set" {
|
||||||
|
cd `chart_dir`
|
||||||
|
local actual=$(helm template \
|
||||||
|
-x templates/server-config-configmap.yaml \
|
||||||
|
--set 'server.extraConfig="{\"hello\": \"world\"}"' \
|
||||||
|
. | tee /dev/stderr |
|
||||||
|
yq '.data["extra-from-values.json"] | match("world") | length' | tee /dev/stderr)
|
||||||
|
[ ! -z "${actual}" ]
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ global:
|
||||||
domain: consul
|
domain: consul
|
||||||
|
|
||||||
server:
|
server:
|
||||||
enabled: null
|
enabled: "-"
|
||||||
image: "consul:1.2.2"
|
image: "consul:1.2.2"
|
||||||
replicas: 3
|
replicas: 3
|
||||||
bootstrapExpect: 3 # Should <= replicas count
|
bootstrapExpect: 3 # Should <= replicas count
|
||||||
|
|
Loading…
Reference in a new issue