test/unit: server Service

This commit is contained in:
Mitchell Hashimoto 2018-09-03 09:02:42 -07:00
parent fc30ae877e
commit 0010bd014b
No known key found for this signature in database
GPG key ID: 744E147AA52F5B0A
2 changed files with 61 additions and 1 deletions

View file

@ -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:

60
test/unit/server-service.bats Executable file
View file

@ -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" ]
}