diff --git a/templates/server-config-configmap.yaml b/templates/server-config-configmap.yaml index d1ed4cd..41b1f2f 100644 --- a/templates/server-config-configmap.yaml +++ b/templates/server-config-configmap.yaml @@ -1,5 +1,5 @@ # 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 kind: ConfigMap metadata: diff --git a/test/_helpers.bash b/test/acceptance/_helpers.bash similarity index 100% rename from test/_helpers.bash rename to test/acceptance/_helpers.bash diff --git a/test/server.bats b/test/acceptance/server.bats similarity index 100% rename from test/server.bats rename to test/acceptance/server.bats diff --git a/test/docker/Test.dockerfile b/test/docker/Test.dockerfile index 93bff9f..51cc166 100644 --- a/test/docker/Test.dockerfile +++ b/test/docker/Test.dockerfile @@ -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 # against a GKE cluster easily. # @@ -19,9 +19,13 @@ RUN apk update && apk add --no-cache --virtual .build-deps \ bash \ openssl \ python \ + py-pip \ git \ jq +# yq +RUN pip install yq + # gcloud 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/' && \ diff --git a/test/unit/_helpers.bash b/test/unit/_helpers.bash new file mode 100644 index 0000000..530b66e --- /dev/null +++ b/test/unit/_helpers.bash @@ -0,0 +1,4 @@ +# chart_dir returns the directory for the chart +chart_dir() { + echo ${BATS_TEST_DIRNAME}/../.. +} diff --git a/test/unit/server.bats b/test/unit/server.bats new file mode 100755 index 0000000..43eb254 --- /dev/null +++ b/test/unit/server.bats @@ -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}" ] +} diff --git a/values.yaml b/values.yaml index dbc256e..0dbdaa3 100644 --- a/values.yaml +++ b/values.yaml @@ -15,7 +15,7 @@ global: domain: consul server: - enabled: null + enabled: "-" image: "consul:1.2.2" replicas: 3 bootstrapExpect: 3 # Should <= replicas count