From 489a396b4cccda16c32ab86d73e26f5190d5809c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 3 Sep 2018 09:15:28 -0700 Subject: [PATCH] test/unit: UI service --- templates/ui-service.yaml | 6 +-- test/unit/ui-service.bats | 94 +++++++++++++++++++++++++++++++++++++++ values.yaml | 7 +-- 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100755 test/unit/ui-service.bats diff --git a/templates/ui-service.yaml b/templates/ui-service.yaml index dddba17..f0c9784 100644 --- a/templates/ui-service.yaml +++ b/templates/ui-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 (and (default .Values.server.enabled .Values.global.enabled) (default .Values.ui.enabled .Values.global.enabled) (default .Values.ui.service .Values.global.enabled)) }} +{{- if (and (or (and (ne (.Values.server.enabled | toString) "-") .Values.server.enabled) (and (eq (.Values.server.enabled | toString) "-") .Values.global.enabled)) (or (and (ne (.Values.ui.enabled | toString) "-") .Values.ui.enabled) (and (eq (.Values.ui.enabled | toString) "-") .Values.global.enabled)) (or (and (ne (.Values.ui.service.enabled | toString) "-") .Values.ui.service.enabled) (and (eq (.Values.ui.service.enabled | toString) "-") .Values.global.enabled))) }} apiVersion: v1 kind: Service metadata: @@ -22,7 +22,7 @@ spec: - name: http port: 80 targetPort: 8500 - {{- if .Values.ui.serviceType }} - type: {{ .Values.ui.serviceType }} + {{- if .Values.ui.service.type }} + type: {{ .Values.ui.service.type }} {{- end }} {{- end }} diff --git a/test/unit/ui-service.bats b/test/unit/ui-service.bats new file mode 100755 index 0000000..df46864 --- /dev/null +++ b/test/unit/ui-service.bats @@ -0,0 +1,94 @@ +#!/usr/bin/env bats + +load _helpers + +@test "ui/Service: enabled by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "ui/Service: enable with global.enabled false" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'global.enabled=false' \ + --set 'server.enabled=true' \ + --set 'ui.enabled=true' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "ui/Service: disable with server.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'server.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "ui/Service: disable with ui.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'ui.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "ui/Service: disable with ui.service.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'ui.service.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "ui/Service: disable with global.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'global.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "ui/Service: disable with global.enabled and server.enabled on" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'global.enabled=false' \ + --set 'server.enabled=true' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "ui/Service: no type by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + . | tee /dev/stderr | + yq -r '.spec.type' | tee /dev/stderr) + [ "${actual}" = "null" ] +} + +@test "ui/Service: specified type" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/ui-service.yaml \ + --set 'ui.service.type=LoadBalancer' \ + . | tee /dev/stderr | + yq -r '.spec.type' | tee /dev/stderr) + [ "${actual}" = "LoadBalancer" ] +} diff --git a/values.yaml b/values.yaml index 192fdf1..7546a17 100644 --- a/values.yaml +++ b/values.yaml @@ -103,15 +103,16 @@ ui: # on the server nodes. This makes UI access via the service below (if # enabled) predictable rather than "any node" if you're running Consul # clients as well. - enabled: null + enabled: "-" # True if you want to create a Service entry for the Consul UI. # # serviceType can be used to control the type of service created. For # example, setting this to "LoadBalancer" will create an external load # balancer (for supported K8S installations) to access the UI. - service: true - serviceType: null + service: + enabled: true + type: null test: image: lachlanevenson/k8s-kubectl