diff --git a/templates/server-service.yaml b/templates/server-service.yaml index 79badf8..ef3b40b 100644 --- a/templates/server-service.yaml +++ b/templates/server-service.yaml @@ -3,7 +3,7 @@ # the agent is installed locally on the node and the NODE_IP should be used. # If the node can't run a Consul agent, then this service can be used to # communicate directly to a server agent. -{{- 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: Service metadata: diff --git a/test/unit/server-service.bats b/test/unit/server-service.bats new file mode 100755 index 0000000..0243149 --- /dev/null +++ b/test/unit/server-service.bats @@ -0,0 +1,60 @@ +#!/usr/bin/env bats + +load _helpers + +@test "server/Service: enabled by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-service.yaml \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "server/Service: enable with global.enabled false" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-service.yaml \ + --set 'global.enabled=false' \ + --set 'server.enabled=true' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "server/Service: disable with server.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-service.yaml \ + --set 'server.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "server/Service: disable with global.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-service.yaml \ + --set 'global.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +# This can be seen as testing just what we put into the YAML raw, but +# this is such an important part of making everything work we verify it here. +@test "server/Service: tolerates unready endpoints" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-service.yaml \ + . | tee /dev/stderr | + yq -r '.metadata.annotations["service.alpha.kubernetes.io/tolerate-unready-endpoints"]' | tee /dev/stderr) + [ "${actual}" = "true" ] + + local actual=$(helm template \ + -x templates/server-service.yaml \ + . | tee /dev/stderr | + yq -r '.spec.publishNotReadyAddresses' | tee /dev/stderr) + [ "${actual}" = "true" ] +}