From f20934a89def40a135ea2aff84c43c8ba2c1c1d8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 3 Sep 2018 09:34:28 -0700 Subject: [PATCH] test/unit: finish inject tests --- templates/connect-inject-mutatingwebhook.yaml | 2 +- templates/connect-inject-service.yaml | 2 +- test/unit/connect-inject-mutatingwebhook.yaml | 43 +++++++++++++++++++ test/unit/connect-inject-service.yaml | 43 +++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100755 test/unit/connect-inject-mutatingwebhook.yaml create mode 100755 test/unit/connect-inject-service.yaml diff --git a/templates/connect-inject-mutatingwebhook.yaml b/templates/connect-inject-mutatingwebhook.yaml index 50ff573..7d95357 100644 --- a/templates/connect-inject-mutatingwebhook.yaml +++ b/templates/connect-inject-mutatingwebhook.yaml @@ -1,5 +1,5 @@ # The MutatingWebhookConfiguration to enable the Connect injector. -{{- if (default .Values.connectInject.enabled .Values.global.enabled) }} +{{- if (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled)) }} apiVersion: admissionregistration.k8s.io/v1beta1 kind: MutatingWebhookConfiguration metadata: diff --git a/templates/connect-inject-service.yaml b/templates/connect-inject-service.yaml index df27d59..86a13ca 100644 --- a/templates/connect-inject-service.yaml +++ b/templates/connect-inject-service.yaml @@ -1,5 +1,5 @@ # The service for the Connect sidecar injector -{{- if (default .Values.connectInject.enabled .Values.global.enabled) }} +{{- if (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled)) }} apiVersion: v1 kind: Service metadata: diff --git a/test/unit/connect-inject-mutatingwebhook.yaml b/test/unit/connect-inject-mutatingwebhook.yaml new file mode 100755 index 0000000..9de2479 --- /dev/null +++ b/test/unit/connect-inject-mutatingwebhook.yaml @@ -0,0 +1,43 @@ +#!/usr/bin/env bats + +load _helpers + +@test "connectInject/MutatingWebhookConfiguration: enabled by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-mutatingwebhook.yaml \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "connectInject/MutatingWebhookConfiguration: enable with global.enabled false" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-mutatingwebhook.yaml \ + --set 'global.enabled=false' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "connectInject/MutatingWebhookConfiguration: disable with connectInject.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-mutatingwebhook.yaml \ + --set 'connectInject.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "connectInject/MutatingWebhookConfiguration: disable with global.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-mutatingwebhook.yaml \ + --set 'global.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} diff --git a/test/unit/connect-inject-service.yaml b/test/unit/connect-inject-service.yaml new file mode 100755 index 0000000..b510e1a --- /dev/null +++ b/test/unit/connect-inject-service.yaml @@ -0,0 +1,43 @@ +#!/usr/bin/env bats + +load _helpers + +@test "connectInject/Service: enabled by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-service.yaml \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "connectInject/Service: enable with global.enabled false" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-service.yaml \ + --set 'global.enabled=false' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "connectInject/Service: disable with connectInject.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-service.yaml \ + --set 'connectInject.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "connectInject/Service: disable with global.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/connect-inject-service.yaml \ + --set 'global.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +}