feat(common): Release common library 3.7.1 (#383)

Co-authored-by: Aisling McGinn <me@aisling.dev>
This commit is contained in:
Bernd Schorgers 2025-02-11 13:23:27 +01:00 committed by GitHub
parent c94a28baa3
commit 433f6d132b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
146 changed files with 232 additions and 222 deletions

View file

@ -0,0 +1,8 @@
---
controllers:
main:
containers:
main:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31

View file

@ -0,0 +1,11 @@
---
# yaml-language-server: $schema=../../../common/values.schema.json
ingress:
main:
hosts:
- host: "chart-example.local"
paths:
- path: /
service:
name: RELEASE-NAME
port: 8081

View file

@ -0,0 +1,19 @@
serviceAccount:
create: true
rbac:
roles:
defaultRole:
type: Role
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]
bindings:
defaultBinding:
type: RoleBinding
roleRef:
identifier: defaultRole
subjects:
- identifier: default

View file

@ -0,0 +1,8 @@
---
# yaml-language-server: $schema=../../../common/values.schema.json
service:
main:
controller: main
ports:
http:
port: 8081

View file

@ -0,0 +1,24 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: Chart validations
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: advancedMounts invalid controller reference should fail
set:
persistence:
data:
type: configMap
name: myConfigMap
advancedMounts:
test:
main:
- path: /data/config.yaml
readOnly: false
mountPropagation: HostToContainer
subPath: config.yaml
asserts:
- failedTemplate:
errorMessage: "No enabled controller found with this identifier. (persistence item: 'data', controller: 'test')"

View file

@ -0,0 +1,238 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: configmap metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
configMaps:
config:
data:
test: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &ConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *ConfigmapDocument
notExists:
path: metadata.annotations
- documentIndex: *ConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
configMaps:
config:
data:
test: test
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &ConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *ConfigmapDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *ConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
configMaps:
config:
data:
test: test
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &ConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *ConfigmapDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *ConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test
- it: default configuration from folder with binary files should fail
set:
configMaps:
config:
data:
test: test
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
asserts:
- failedTemplate:
errorMessage: "There was an error loading ConfigMap: test_2. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`"
- it: default metadata from folder should pass
set:
configMaps:
config:
data:
test: test
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- hasDocuments:
count: 4
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
notExists:
path: metadata.annotations
- documentIndex: *FirstConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
notExists:
path: metadata.annotations
- documentIndex: *SecondConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- documentIndex: &ThirdConfigmapDocument 2
isKind:
of: ConfigMap
- documentIndex: *ThirdConfigmapDocument
notExists:
path: metadata.annotations
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata from folder should pass
set:
configMaps:
config:
data:
test: test
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
labels:
test: test_label
annotations:
test: test_annotation
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- hasDocuments:
count: 4
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- documentIndex: &ThirdConfigmapDocument 2
isKind:
of: ConfigMap
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test: test_label
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.annotations
value:
test: test_annotation

View file

@ -0,0 +1,196 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: configMap names
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: ConfigMap
- it: with disabled configMap should pass
set:
configMaps:
config:
enabled: false
data:
test: test
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: ConfigMap
- it: with multiple configMap should pass
set:
configMaps:
config:
data:
foo: bar
secondary:
data:
test: test
asserts:
- hasDocuments:
count: 3
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
isNotNullOrEmpty:
path: metadata.name
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
isNotNullOrEmpty:
path: metadata.name
- it: default name should pass
set:
configMaps:
config:
data:
test: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &ConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *ConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME-config
- it: with nameOverride should pass
set:
configMaps:
config:
data:
test: test
nameOverride: http
asserts:
- hasDocuments:
count: 2
- documentIndex: &ConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *ConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME-http
- it: with templated nameOverride should pass
set:
configMaps:
config:
data:
test: test
nameOverride: "{{ .Release.Name }}"
asserts:
- hasDocuments:
count: 2
- documentIndex: &ConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *ConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME
- it: with templated nameOverride and from folder should pass
set:
configMaps:
config:
data:
test: test
nameOverride: "{{ .Release.Name }}"
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- hasDocuments:
count: 4
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME-test_1
- documentIndex: &ThirdConfigmapDocument 2
isKind:
of: ConfigMap
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME-test_2
- it: with templated nameOverride and from folder with forceRename should pass
set:
configMaps:
config:
data:
test: test
nameOverride: "{{ .Release.Name }}"
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_1:
forceRename: &newName1 newName1
test_2:
forceRename: &newName2 newName2
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- hasDocuments:
count: 4
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
equal:
path: metadata.name
value: *newName1
- documentIndex: &ThirdConfigmapDocument 2
isKind:
of: ConfigMap
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.name
value: *newName2

View file

@ -0,0 +1,73 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: configmap Pod metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
configMaps:
config:
enabled: true
data:
test: value 1
test_default_enabled:
data:
test: value 1
test_not_in_checksum:
includeInChecksum: false
data:
test: value 1
test_disabled:
enabled: false
data:
test: value 1
asserts:
- documentIndex: &ControllerDoc 3
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: spec.template.metadata.annotations
value:
checksum/configMaps: 66d23d7a53c4e2a523ba85a969696b4ebb78ec5d79ab9c12c210c1569f48511b
- it: default metadata from folder should pass
set:
configMaps:
config:
enabled: true
data:
test: value 1
test_default_enabled:
data:
test: value 1
test_not_in_checksum:
includeInChecksum: false
data:
test: value 1
test_disabled:
enabled: false
data:
test: value 1
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- documentIndex: &ControllerDoc 5
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: spec.template.metadata.annotations
value:
checksum/configMaps: e83a24569d0b4f2ccc44aec36d4e9a1c44a29bcc92eefdffe14fb1ce81dff054

View file

@ -0,0 +1,109 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container args override
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].args
- it: single string should pass
set:
controllers.main.containers.main.args: sleep infinity
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].args
value:
- sleep infinity
- it: multiline string should pass
set:
controllers.main.containers.main.args: |
echo hello
echo world
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].args
value:
- |-
echo hello
echo world
- it: single quoted string should pass
set:
controllers.main.containers.main.args: "sleep infinity"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].args
value:
- sleep infinity
- it: list of strings should pass
set:
controllers.main.containers.main.args:
- sleep
- infinity
- "test"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].args
value:
- sleep
- infinity
- test
- it: args from defaultContainerOptions should pass
set:
controllers.main.defaultContainerOptions:
args: value_of_args
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].args
value:
- value_of_args
- it: args from defaultContainerOptions with container override should pass
set:
controllers.main.defaultContainerOptions:
args: value_of_args
controllers.main.containers.main.args:
- value 1
- value 2
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].args
value:
- value 1
- value 2

View file

@ -0,0 +1,107 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container command override
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].command
- it: single string should pass
set:
controllers.main.containers.main.command: /bin/sh
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].command
value:
- /bin/sh
- it: multiline string should pass
set:
controllers.main.containers.main.command: |
/bin/sh
-c
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].command
value:
- |-
/bin/sh
-c
- it: single quoted string should pass
set:
controllers.main.containers.main.command: "/bin/sh"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].command
value:
- /bin/sh
- it: list of strings should pass
set:
controllers.main.containers.main.command:
- /bin/sh
- "-c"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].command
value:
- /bin/sh
- -c
- it: command from defaultContainerOptions should pass
set:
controllers.main.defaultContainerOptions:
command: value_of_command
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].command
value:
- value_of_command
- it: command from defaultContainerOptions with container override should pass
set:
controllers.main.defaultContainerOptions:
command: value_of_command
controllers.main.containers.main.command:
- value 1
- value 2
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].command
value:
- value 1
- value 2

View file

@ -0,0 +1,273 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container env values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
notExists:
path: spec.template.spec.containers[0].env
- it: KeyValue string should pass
set:
controllers.main.containers.main.env:
string: value_of_env
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: string
value: value_of_env
- it: KeyValue float should pass
set:
controllers.main.containers.main.env:
string: 4.2
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: string
value: "4.2"
- it: KeyValue int should pass
set:
controllers.main.containers.main.env:
string: 1
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: string
value: "1"
- it: List should pass
set:
controllers.main.containers.main.env:
- name: STATIC_ENV_FROM_LIST
value: STATIC_ENV_VALUE_FROM_LIST
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: STATIC_ENV_FROM_LIST
value: STATIC_ENV_VALUE_FROM_LIST
- it: Explicit ValueFrom in list should pass
set:
controllers.main.containers.main.env:
- name: DYNAMIC_ENV_FROM_LIST
valueFrom:
fieldRef:
fieldPath: spec.nodeName
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: DYNAMIC_ENV_FROM_LIST
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- it: Implicit ValueFrom in list should pass
set:
controllers.main.containers.main.env:
- name: DYNAMIC_ENV_FROM_LIST
fieldRef:
fieldPath: spec.nodeName
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: DYNAMIC_ENV_FROM_LIST
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- it: Implicit ValueFrom should pass
set:
controllers.main.containers.main.env:
DYNAMIC_ENV:
fieldRef:
fieldPath: spec.nodeName
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: DYNAMIC_ENV
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- it: Templated value should pass
set:
controllers.main.containers.main.env:
DYNAMIC_ENV: "{{ .Release.Name }}-admin"
TEMPLATE_ENV:
valueFrom:
secretKeyRef:
name: "{{ .Release.Name }}-secret"
key: "{{ .Release.Name }}-key"
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: DYNAMIC_ENV
value: RELEASE-NAME-admin
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[1]
value:
name: TEMPLATE_ENV
valueFrom:
secretKeyRef:
key: "RELEASE-NAME-key"
name: "RELEASE-NAME-secret"
- it: Combined KeyValue with Explicit ValueFrom should pass
set:
controllers.main.containers.main.env:
STATIC_ENV: static
DYNAMIC_ENV:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: DYNAMIC_ENV
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[1]
value:
name: STATIC_ENV
value: static
- it: Env vars with dependsOn should pass
set:
controllers.main.containers.main.env:
STATIC_ENV: 1
DYNAMIC_ENV:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
dependsOn: STATIC_ENV
ORDERED_ENV:
value: true
dependsOn: STATIC_ENV
DEPENDENT_ENV:
value: moo_two
dependsOn:
- DYNAMIC_ENV
- ORDERED_ENV
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: STATIC_ENV
value: "1"
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[1]
value:
name: DYNAMIC_ENV
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[2]
value:
name: ORDERED_ENV
value: "true"
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[3]
value:
name: DEPENDENT_ENV
value: moo_two
- it: env from defaultContainerOptions should pass
set:
controllers.main.defaultContainerOptions:
env:
string: value_of_env
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: string
value: value_of_env
- it: env from defaultContainerOptions with container override should pass
set:
controllers.main.defaultContainerOptions:
env:
string: value_of_env
controllers.main.containers.main.env:
someThingElse: value_of_env
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: someThingElse
value: value_of_env

View file

@ -0,0 +1,195 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container envFrom values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
notExists:
path: spec.template.spec.containers[0].envFrom
- it: explicit envFrom should pass
set:
controllers.main.containers.main.envFrom:
- secretRef:
name: myCustomSecret
prefix: test
- configMapRef:
name: myCustomConfig
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[0]
value:
secretRef:
name: myCustomSecret
prefix: test
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[1]
value:
configMapRef:
name: myCustomConfig
- it: envFrom from defaultContainerOptions should pass
set:
controllers.main.defaultContainerOptions:
envFrom:
- secretRef:
name: myCustomSecret
prefix: test
- configMapRef:
name: myCustomConfig
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[0]
value:
secretRef:
name: myCustomSecret
prefix: test
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[1]
value:
configMapRef:
name: myCustomConfig
- it: envFrom from defaultContainerOptions with container override should pass
set:
controllers.main.defaultContainerOptions:
envFrom:
- secretRef:
name: myCustomSecret
prefix: test
- configMapRef:
name: myCustomConfig
controllers.main.containers.main.envFrom:
- secretRef:
name: myCustomSecretOverride
prefix: test
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[0]
value:
secretRef:
name: myCustomSecretOverride
prefix: test
- documentIndex: *DeploymentDoc
notExists:
path: spec.template.spec.containers[0].envFrom[1]
- it: envFrom configmap identifier reference should pass
set:
controllers.main.containers.main.envFrom:
- configMap: config
prefix: test
- configMapRef:
identifier: config
configMaps:
config:
data:
test: test
asserts:
- documentIndex: &DeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[0]
value:
configMapRef:
name: RELEASE-NAME-config
prefix: test
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[1]
value:
configMapRef:
name: RELEASE-NAME-config
- it: envFrom Secret identifier reference should pass
set:
controllers.main.containers.main.envFrom:
- secret: secret
prefix: test
- secretRef:
identifier: secret
prefix: test
secrets:
secret:
stringData:
test: test
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[0]
value:
secretRef:
name: RELEASE-NAME-secret
prefix: test
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[1]
value:
secretRef:
name: RELEASE-NAME-secret
prefix: test
- it: envFrom with templated name reference should pass
set:
controllers.main.containers.main.envFrom:
- configMap: "{{ .Release.Name }}-config"
- configMapRef:
name: "{{ .Release.Name }}-config2"
- secret: "{{ .Release.Name }}-secret"
- secretRef:
name: "{{ .Release.Name }}-secret2"
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[0]
value:
configMapRef:
name: RELEASE-NAME-config
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[1]
value:
configMapRef:
name: RELEASE-NAME-config2
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[2]
value:
secretRef:
name: RELEASE-NAME-secret
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].envFrom[3]
value:
secretRef:
name: RELEASE-NAME-secret2

View file

@ -0,0 +1,88 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container image tag
templates:
- common.yaml
tests:
- it: string tag should pass
values:
- ../_values/controllers_main_default_container.yaml
set:
controllers.main.containers.main.image:
repository: ghcr.io/mendhak/http-https-echo
tag: latest
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/mendhak/http-https-echo:latest
- it: integer tag should pass
values:
- ../_values/controllers_main_default_container.yaml
set:
controllers.main.containers.main.image:
repository: ghcr.io/mendhak/http-https-echo
tag: 1.23
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/mendhak/http-https-echo:1.23
- it: template tag should pass
values:
- ../_values/controllers_main_default_container.yaml
set:
controllers.main.containers.main.image:
repository: ghcr.io/mendhak/http-https-echo
tag: "{{.Chart.Version}}"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/mendhak/http-https-echo:1.0.0
- it: tag from defaultContainerOptions should pass
set:
controllers.main:
defaultContainerOptions:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 32
containers:
main: {} # needed to have at least a container enabled
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/mendhak/http-https-echo:32
- it: tag from defaultContainerOptions with container override should pass
set:
controllers.main.defaultContainerOptions.image:
repository: ghcr.io/mendhak/http-https-echo
tag: 32
controllers.main.containers.main.image:
repository: ghcr.io/mendhak/http-https-echo-override
tag: 33
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/mendhak/http-https-echo-override:33

View file

@ -0,0 +1,142 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container resources
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].resources
- it: defaultContainerOption should pass
set:
controllers:
main:
defaultContainerOptions:
resources:
requests:
memory: 1Gi
initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 1Gi
- documentIndex: 0
equal:
path: spec.template.spec.initContainers[0].resources
value:
requests:
memory: 1Gi
- it: defaultContainerOption with container override should pass
set:
controllers:
main:
defaultContainerOptions:
resources:
requests:
memory: 1Gi
containers:
main:
resources:
requests:
memory: 2Gi
initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 2Gi
- documentIndex: 0
equal:
path: spec.template.spec.initContainers[0].resources
value:
requests:
memory: 1Gi
- it: defaultContainerOption with initContainer override should pass
set:
controllers:
main:
defaultContainerOptions:
resources:
requests:
memory: 1Gi
initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
resources:
requests:
memory: 2Gi
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 1Gi
- documentIndex: 0
equal:
path: spec.template.spec.initContainers[0].resources
value:
requests:
memory: 2Gi
- it: defaultContainerOption disabled for initContainer should pass
set:
controllers:
main:
applyDefaultContainerOptionsToInitContainers: false
defaultContainerOptions:
resources:
requests:
memory: 1Gi
initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 1Gi
- documentIndex: 0
notExists:
path: spec.template.spec.initContainers[0].resources

View file

@ -0,0 +1,31 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container restartPolicy
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].restartPolicy
- it: custom restartPolicy should pass
set:
controllers.main.containers:
main:
restartPolicy: Always
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].restartPolicy
value: Always

View file

@ -0,0 +1,59 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container securityContext
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].securityContext
- it: defaultContainerOption should pass
set:
controllers:
main:
defaultContainerOptions:
securityContext:
runAsUser: 1000
runAsGroup: 1000
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].securityContext
value:
runAsUser: 1000
runAsGroup: 1000
- it: defaultContainerOption with container override should pass
set:
controllers:
main:
defaultContainerOptions:
securityContext:
runAsUser: 1000
runAsGroup: 1000
containers:
main:
securityContext:
runAsUser: 568
runAsGroup: 568
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].securityContext
value:
runAsUser: 568
runAsGroup: 568

View file

@ -0,0 +1,30 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container stdin
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].stdin
- it: custom stdin should pass
set:
controllers.main.containers:
main:
stdin: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].stdin
value: true

View file

@ -0,0 +1,30 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container tty
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].tty
- it: custom tty should pass
set:
controllers.main.containers:
main:
tty: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].tty
value: true

View file

@ -0,0 +1,54 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container name
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: with explicit name should pass
set:
controllers.main.containers:
main:
nameOverride: template-test
image:
repository: ghcr.io/mendhak/http-https-echo
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].name
value: template-test
- it: with implicit name should pass
set:
controllers.main.containers:
main:
image:
repository: ghcr.io/mendhak/http-https-echo
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].name
value: main
- it: with templated name should pass
set:
controllers.main.containers:
main:
nameOverride: "{{ .Release.Name }}-container"
image:
repository: ghcr.io/mendhak/http-https-echo
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].name
value: RELEASE-NAME-container

View file

@ -0,0 +1,39 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container ports
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].ports
- it: custom port should pass
set:
controllers:
main:
containers:
main:
ports:
- containerPort: 8080
name: http
protocol: TCP
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].ports[0]
value:
containerPort: 8080
name: http
protocol: TCP

View file

@ -0,0 +1,437 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container probes
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
- ../_values/service_main_default.yaml
set:
controllers.main.containers.main.probes.liveness.enabled: true
controllers.main.containers.main.probes.readiness.enabled: true
controllers.main.containers.main.probes.startup.enabled: true
tests:
- it: default probes
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 8081
timeoutSeconds: 1
- equal:
path: spec.template.spec.containers[0].readinessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 8081
timeoutSeconds: 1
- equal:
path: spec.template.spec.containers[0].startupProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 8081
timeoutSeconds: 1
- it: custom primary port gets picked up by probes
set:
service.main.ports.test:
enabled: true
primary: true
port: 8080
documentSelector: *DeploymentSelector
asserts:
- documentIndex: 0
isKind:
of: Deployment
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 8080
timeoutSeconds: 1
- equal:
path: spec.template.spec.containers[0].readinessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 8080
timeoutSeconds: 1
- equal:
path: spec.template.spec.containers[0].startupProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 8080
timeoutSeconds: 1
- it: probes with string Service port
set:
service.main.ports.http.port: "80"
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 80
timeoutSeconds: 1
- equal:
path: spec.template.spec.containers[0].readinessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 80
timeoutSeconds: 1
- equal:
path: spec.template.spec.containers[0].startupProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: 80
timeoutSeconds: 1
- it: multiple services are handled correctly
set:
controllers:
other:
containers:
main:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
pullPolicy: IfNotPresent
probes:
liveness:
enabled: true
readiness:
enabled: true
startup:
enabled: true
service:
other:
controller: other
ports:
http:
enabled: true
port: 8080
asserts:
- documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-main
equal:
path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port
value: 8081
- documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-main
equal:
path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port
value: 8081
- documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-main
equal:
path: spec.template.spec.containers[0].startupProbe.tcpSocket.port
value: 8081
- documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-other
equal:
path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port
value: 8080
- documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-other
equal:
path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port
value: 8080
- documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-other
equal:
path: spec.template.spec.containers[0].startupProbe.tcpSocket.port
value: 8080
- it: no probes are defined when services are disabled
set:
service:
main:
enabled: false
controller: main
documentSelector: *DeploymentSelector
asserts:
- notExists:
path: spec.template.spec.containers[0].livenessProbe
- notExists:
path: spec.template.spec.containers[0].readinessProbe
- notExists:
path: spec.template.spec.containers[0].startupProbe
- it: AUTO type probe can be configured
set:
service.main.ports.http.protocol: HTTP
controllers.main.containers.main.probes:
liveness:
enabled: true
type: AUTO
path: /api/version
documentSelector: *DeploymentSelector
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe
value:
httpGet:
path: /api/version
port: 8081
scheme: HTTP
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: HTTP type probe can be configured
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
type: HTTP
path: /api/version
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
httpGet:
path: /api/version
port: 8081
scheme: HTTP
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: HTTPS type probe can be configured
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
type: HTTPS
path: /api/version
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
httpGet:
path: /api/version
port: 8081
scheme: HTTPS
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: GRPC type probe can be configured without service
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
type: GRPC
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
grpc:
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: GRPC type probe can be configured with service
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
type: GRPC
service: test
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
grpc:
port: 8081
service: test
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: custom liveness probe can be configured
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
custom: true
spec:
httpGet:
path: /api/version
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
httpGet:
path: /api/version
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: custom readiness probe can be configured
set:
controllers.main.containers.main.probes:
readiness:
enabled: true
custom: true
spec:
httpGet:
path: /api/version
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].readinessProbe
value:
httpGet:
path: /api/version
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: custom startup probe can be configured
set:
controllers.main.containers.main.probes:
startup:
enabled: true
custom: true
spec:
httpGet:
path: /api/version
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].startupProbe
value:
httpGet:
path: /api/version
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: User-defined liveness probe port can be configured
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
port: http
documentSelector: *DeploymentSelector
asserts:
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: http
timeoutSeconds: 1
- it: User-defined readiness probe port can be configured
set:
controllers.main.containers.main.probes:
readiness:
enabled: true
port: http
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].readinessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: http
timeoutSeconds: 1
- it: User-defined startup probe port can be configured
set:
controllers.main.containers.main.probes:
startup:
enabled: true
port: http
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].startupProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: http
timeoutSeconds: 1

View file

@ -0,0 +1,33 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: Container validations
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: image repository is required
set:
controllers:
main:
containers:
test:
image:
repository: ""
tag: "test"
asserts:
- failedTemplate:
errorMessage: "No image repository specified for container. (controller main, container test)"
- it: image tag is required
set:
controllers:
main:
containers:
test:
image:
repository: test
tag: ""
asserts:
- failedTemplate:
errorMessage: "No image tag specified for container. (controller main, container test)"

View file

@ -0,0 +1,291 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container volumeMounts
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: no persistence should pass
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
notExists:
path: spec.template.spec.containers[0].volumeMounts
- it: default should pass
set:
persistence:
config:
accessMode: ReadWriteOnce
size: 1Gi
asserts:
- documentIndex: &DeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: config
mountPath: /config
- it: advanced mount config should pass
set:
controllers:
main:
containers:
second-container:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
second:
containers:
first-container:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
persistence:
data:
type: configMap
name: myConfigMap
globalMounts:
- path: /globalTest
advancedMounts:
main:
main:
- path: /data/config.yaml
readOnly: false
mountPropagation: HostToContainer
subPath: config.yaml
second-container:
- path: /appdata/config
readOnly: true
second:
first-container:
- path: /second-pod/config.yaml
readOnly: false
subPath: config.yaml
asserts:
- documentIndex: &FirstDeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *FirstDeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /globalTest
name: data
- mountPath: /data/config.yaml
name: data
subPath: config.yaml
mountPropagation: HostToContainer
- documentIndex: *FirstDeploymentDoc
equal:
path: spec.template.spec.containers[1].volumeMounts
value:
- mountPath: /globalTest
name: data
- mountPath: /appdata/config
name: data
readOnly: true
- documentIndex: &SecondDeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *SecondDeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /globalTest
name: data
- mountPath: /second-pod/config.yaml
name: data
subPath: config.yaml
- it: emptyDir should pass
set:
persistence:
cache:
type: emptyDir
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: cache
mountPath: /cache
- it: custom mountPath should pass
set:
persistence:
config:
accessMode: ReadWriteMany
size: 1G
globalMounts:
- path: /custom
asserts:
- documentIndex: &DeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: config
mountPath: /custom
- it: mount with subPath should pass
set:
persistence:
config:
existingClaim: myClaim
globalMounts:
- path: /config
subPath: "mySubPath"
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: config
mountPath: /config
subPath: mySubPath
- it: hostPath with custom mountPath should pass
set:
persistence:
config:
type: hostPath
hostPath: /tmp
globalMounts:
- path: /data
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: config
mountPath: /data
- it: hostPath mount with subPath should pass
set:
persistence:
config:
type: hostPath
hostPath: /dev
globalMounts:
- subPath: mySubPath
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: config
mountPath: /dev
subPath: mySubPath
- it: volumeClaimTemplates with default mounts should pass
set:
controllers.main:
type: statefulset
statefulset:
volumeClaimTemplates:
- name: "storage"
accessMode: "ReadWriteOnce"
size: "10Gi"
storageClass: "storage"
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: storage
mountPath: /storage
- it: volumeClaimTemplates with globalMounts should pass
set:
controllers.main:
type: statefulset
statefulset:
volumeClaimTemplates:
- name: "storage"
accessMode: "ReadWriteOnce"
size: "10Gi"
storageClass: "storage"
globalMounts:
- path: /tmp/storage
- path: /tmp/secondMountPoint
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[0]
value:
name: storage
mountPath: /tmp/storage
- documentIndex: *StatefulSetDoc
equal:
path: spec.template.spec.containers[0].volumeMounts[1]
value:
name: storage
mountPath: /tmp/secondMountPoint
- it: volumeClaimTemplates with advancedMounts should pass
set:
controllers.main:
type: statefulset
statefulset:
volumeClaimTemplates:
- name: "storage"
accessMode: "ReadWriteOnce"
size: "10Gi"
storageClass: "storage"
advancedMounts:
second-container:
- path: /tmp/storage
- path: /tmp/secondMountPoint
containers:
second-container:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
notExists:
path: spec.template.spec.containers[0].volumeMounts
- documentIndex: *StatefulSetDoc
equal:
path: spec.template.spec.containers[1].volumeMounts[0]
value:
name: storage
mountPath: /tmp/storage
- documentIndex: *StatefulSetDoc
equal:
path: spec.template.spec.containers[1].volumeMounts[1]
value:
name: storage
mountPath: /tmp/secondMountPoint

View file

@ -0,0 +1,40 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: container workingDir override
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].workingDir
- it: string should pass
set:
controllers.main.containers.main.workingDir: /work
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].workingDir
value: /work
- it: quoted string should pass
set:
controllers.main.containers.main.workingDir: "/work"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].workingDir
value: /work

View file

@ -0,0 +1,95 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: cronjob configuration
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default cronjob configuration should pass
set:
controllers.main.type: cronjob
controllers.main.cronjob.schedule: "*/20 * * * *"
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
equal:
path: spec.suspend
value: false
- documentIndex: *ControllerDoc
equal:
path: spec.schedule
value: "*/20 * * * *"
- documentIndex: *ControllerDoc
equal:
path: spec.concurrencyPolicy
value: Forbid
- documentIndex: *ControllerDoc
equal:
path: spec.successfulJobsHistoryLimit
value: 1
- documentIndex: *ControllerDoc
equal:
path: spec.failedJobsHistoryLimit
value: 1
- documentIndex: *ControllerDoc
notExists:
path: spec.jobTemplate.spec.ttlSecondsAfterFinished
- documentIndex: *ControllerDoc
equal:
path: spec.jobTemplate.spec.template.spec.restartPolicy
value: Never
- it: custom cronjob configuration should pass
set:
controllers:
main:
type: cronjob
pod:
restartPolicy: OnFailure
cronjob:
suspend: &CronJobSuspended true
schedule: &CronJobSchedule "0 3 * * *"
concurrencyPolicy: &CronJobConcurrencyPolicy "Test"
failedJobsHistory: &CronJobFailedJobsHistory 2
successfulJobsHistory: &CronJobSuccessfulJobsHistory 3
ttlSecondsAfterFinished: &ttlSecondsAfterFinished 3600
parallelism: &CronJobParallelism 3
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
equal:
path: spec.suspend
value: *CronJobSuspended
- documentIndex: *ControllerDoc
equal:
path: spec.schedule
value: *CronJobSchedule
- documentIndex: *ControllerDoc
equal:
path: spec.concurrencyPolicy
value: *CronJobConcurrencyPolicy
- documentIndex: *ControllerDoc
equal:
path: spec.successfulJobsHistoryLimit
value: *CronJobSuccessfulJobsHistory
- documentIndex: *ControllerDoc
equal:
path: spec.failedJobsHistoryLimit
value: *CronJobFailedJobsHistory
- documentIndex: *ControllerDoc
equal:
path: spec.jobTemplate.spec.ttlSecondsAfterFinished
value: *ttlSecondsAfterFinished
- documentIndex: *ControllerDoc
equal:
path: spec.jobTemplate.spec.template.spec.restartPolicy
value: OnFailure
- documentIndex: *ControllerDoc
equal:
path: spec.jobTemplate.spec.parallelism
value: *CronJobParallelism

View file

@ -0,0 +1,136 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller defaultContainerOptions
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].resources
- it: defaultContainerOption with implicit strategy should pass
set:
controllers.main.defaultContainerOptions:
resources:
requests:
memory: 1Gi
cpu: 150m
controllers.main.containers.main.resources:
requests:
memory: 2Gi
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 2Gi
- it: defaultContainerOption with overwrite strategy should pass
set:
controllers.main.defaultContainerOptionsStrategy: overwrite
controllers.main.defaultContainerOptions:
resources:
requests:
memory: 1Gi
cpu: 150m
controllers.main.containers.main.resources:
requests:
memory: 2Gi
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 2Gi
- it: defaultContainerOption with merge strategy should pass
set:
controllers.main.defaultContainerOptionsStrategy: merge
controllers.main.defaultContainerOptions:
resources:
requests:
memory: 1Gi
cpu: 150m
controllers.main.containers.main.resources:
requests:
memory: 2Gi
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 2Gi
cpu: 150m
- it: Default applyDefaultContainerOptionsToInitContainers (true) should pass
set:
controllers.main.defaultContainerOptions:
resources:
requests:
memory: 1Gi
controllers.main.initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 1Gi
- documentIndex: 0
equal:
path: spec.template.spec.initContainers[0].resources
value:
requests:
memory: 1Gi
- it: applyDefaultContainerOptionsToInitContainers false should pass
set:
controllers.main.applyDefaultContainerOptionsToInitContainers: false
controllers.main.defaultContainerOptions:
resources:
requests:
memory: 1Gi
controllers.main.initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: 1Gi
- documentIndex: 0
notExists:
path: spec.template.spec.initContainers[0].resources

View file

@ -0,0 +1,130 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller revisionHistoryLimit
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
# Deployment
- it: default should pass for Deployment
set:
controllers.main.type: deployment
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 3
- it: custom revisionHistoryLimit should pass for Deployment
set:
controllers.main:
type: deployment
revisionHistoryLimit: 8
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 8
- it: explicit revisionHistoryLimit 0 should pass for Deployment
set:
controllers.main:
type: deployment
revisionHistoryLimit: 0
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 0
# StatefulSet
- it: default should pass for StatefulSet
set:
controllers.main.type: statefulset
asserts:
- documentIndex: 0
isKind:
of: StatefulSet
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 3
- it: custom revisionHistoryLimit should pass for StatefulSet
set:
controllers.main:
type: statefulset
revisionHistoryLimit: 8
asserts:
- documentIndex: 0
isKind:
of: StatefulSet
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 8
- it: explicit revisionHistoryLimit 0 should pass for StatefulSet
set:
controllers.main:
type: statefulset
revisionHistoryLimit: 0
asserts:
- documentIndex: 0
isKind:
of: StatefulSet
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 0
# DaemonSet
- it: default should pass for DaemonSet
set:
controllers.main.type: daemonset
asserts:
- documentIndex: 0
isKind:
of: DaemonSet
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 3
- it: custom revisionHistoryLimit should pass for DaemonSet
set:
controllers.main:
type: daemonset
revisionHistoryLimit: 8
asserts:
- documentIndex: 0
isKind:
of: DaemonSet
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 8
- it: explicit revisionHistoryLimit 0 should pass for DaemonSet
set:
controllers.main:
type: daemonset
revisionHistoryLimit: 0
asserts:
- documentIndex: 0
isKind:
of: DaemonSet
- documentIndex: 0
equal:
path: spec.revisionHistoryLimit
value: 0

View file

@ -0,0 +1,65 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: job configuration
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default job configuration should pass
set:
controllers:
main:
type: job
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Job
- documentIndex: *ControllerDoc
equal:
path: spec.suspend
value: false
- documentIndex: *ControllerDoc
notExists:
path: spec.ttlSecondsAfterFinished
- documentIndex: *ControllerDoc
equal:
path: spec.template.spec.restartPolicy
value: Never
- it: custom job configuration should pass
set:
controllers:
main:
type: job
pod:
restartPolicy: OnFailure
job:
suspend: &JobSuspended true
ttlSecondsAfterFinished: &ttlSecondsAfterFinished 3600
backoffLimit: 3
parallelism: &JobParallelism 3
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Job
- documentIndex: *ControllerDoc
equal:
path: spec.suspend
value: *JobSuspended
- documentIndex: *ControllerDoc
equal:
path: spec.ttlSecondsAfterFinished
value: *ttlSecondsAfterFinished
- documentIndex: *ControllerDoc
equal:
path: spec.template.spec.restartPolicy
value: OnFailure
- documentIndex: *ControllerDoc
equal:
path: spec.backoffLimit
value: 3
- documentIndex: *ControllerDoc
equal:
path: spec.parallelism
value: *JobParallelism

View file

@ -0,0 +1,123 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller metadata cronjob
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
controllers.main.cronjob.schedule: "*/20 * * * *"
tests:
- it: default metadata should pass
set:
controllers.main.type: cronjob
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
notExists:
path: metadata.annotations
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
controllers:
main:
type: cronjob
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
controllers:
main:
type: cronjob
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test
- it: jobTemplate metadata should pass
set:
controllers:
main:
type: cronjob
pod:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
equal:
path: spec.jobTemplate.spec.template.metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: spec.jobTemplate.spec.template.metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME
test_label: test

View file

@ -0,0 +1,92 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller metadata daemonset
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
controllers.main.type: daemonset
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: DaemonSet
- documentIndex: *ControllerDoc
notExists:
path: metadata.annotations
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
controllers:
main:
type: daemonset
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: DaemonSet
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
controllers:
main:
type: daemonset
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: DaemonSet
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,92 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller metadata deployment
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
controllers.main.type: deployment
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Deployment
- documentIndex: *ControllerDoc
notExists:
path: metadata.annotations
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
controllers:
main:
type: deployment
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
controllers:
main:
type: deployment
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,120 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller metadata job
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
controllers.main.type: job
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Job
- documentIndex: *ControllerDoc
notExists:
path: metadata.annotations
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
controllers:
main:
type: job
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Job
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
controllers:
main:
type: job
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Job
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test
- it: jobTemplate metadata should pass
set:
controllers:
main:
type: job
pod:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Job
- documentIndex: *ControllerDoc
equal:
path: spec.template.metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME
test_label: test

View file

@ -0,0 +1,92 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller metadata statefulset
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
controllers.main.type: statefulset
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: StatefulSet
- documentIndex: *ControllerDoc
notExists:
path: metadata.annotations
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
controllers:
main:
type: statefulset
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: StatefulSet
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
controllers:
main:
type: statefulset
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: StatefulSet
- documentIndex: *ControllerDoc
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *ControllerDoc
equal:
path: metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,138 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: controller types
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: *deploymentDoc
equal:
path: metadata.labels['app.kubernetes.io/component']
value: main
- it: additional controllers should pass
set:
controllers:
second:
containers:
main:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- hasDocuments:
count: 2
- documentIndex: &firstDeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *firstDeploymentDoc
equal:
path: metadata.name
value: RELEASE-NAME-main
- documentIndex: *firstDeploymentDoc
equal:
path: metadata.labels['app.kubernetes.io/component']
value: main
- documentIndex: &secondDeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *secondDeploymentDoc
equal:
path: metadata.name
value: RELEASE-NAME-second
- documentIndex: *secondDeploymentDoc
equal:
path: metadata.labels['app.kubernetes.io/component']
value: second
- it: additional controllers with nameOverride should pass
set:
controllers:
main:
nameOverride: "{{ .Release.Name }}"
second:
nameOverride: testOverride
containers:
main:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
asserts:
- hasDocuments:
count: 2
- documentIndex: &firstDeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *firstDeploymentDoc
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: *firstDeploymentDoc
equal:
path: metadata.labels['app.kubernetes.io/component']
value: main
- documentIndex: &secondDeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *secondDeploymentDoc
equal:
path: metadata.name
value: RELEASE-NAME-testOverride
- documentIndex: *secondDeploymentDoc
equal:
path: metadata.labels['app.kubernetes.io/component']
value: second
- it: daemonset should pass
set:
controllers.main.type: daemonset
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: DaemonSet
- documentIndex: *ControllerDoc
equal:
path: metadata.name
value: RELEASE-NAME
- it: statefulset should pass
set:
controllers.main.type: statefulset
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: StatefulSet
- documentIndex: *ControllerDoc
equal:
path: metadata.name
value: RELEASE-NAME
- it: cronjob should pass
set:
controllers.main.type: cronjob
controllers.main.cronjob.schedule: "*/20 * * * *"
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: CronJob
- documentIndex: *ControllerDoc
equal:
path: metadata.name
value: RELEASE-NAME
- it: disabled should pass
set:
controllers.main.enabled: false
asserts:
- hasDocuments:
count: 0

View file

@ -0,0 +1,115 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: ingress metadata
templates:
- common.yaml
values:
- ../_values/ingress_main_default_hosts.yaml
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
notExists:
path: metadata.annotations
- documentIndex: *IngressDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
ingress.main:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *IngressDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
ingress.main:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *IngressDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with templates should pass
set:
ingress.main:
annotations:
template_annotation1: "{{ .Release.Name | lower }}"
template_annotation2: "{{ .Chart.Name | lower }}"
labels:
template_label1: "{{ .Release.Name | lower }}"
template_label2: "{{ .Chart.Name | lower }}"
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: metadata.annotations["template_annotation1"]
value: release-name
- documentIndex: *IngressDocument
equal:
path: metadata.annotations["template_annotation2"]
value: common-test
- documentIndex: *IngressDocument
equal:
path: metadata.labels["template_label1"]
value: release-name
- documentIndex: *IngressDocument
equal:
path: metadata.labels["template_label2"]
value: common-test

View file

@ -0,0 +1,113 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: ingress presence
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: Ingress
- it: explicitly disabled should pass
values:
- ../_values/ingress_main_default_hosts.yaml
set:
ingress.main.enabled: false
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: Ingress
- it: explicitly enabled should pass
values:
- ../_values/ingress_main_default_hosts.yaml
set:
ingress.main.enabled: true
asserts:
- hasDocuments:
count: 2
- documentIndex: 0
not: true
isKind:
of: Ingress
- documentIndex: 1
isKind:
of: Ingress
- it: multiple ingress should pass
values:
- ../_values/service_main_default.yaml
- ../_values/ingress_main_default_hosts.yaml
set:
ingress.test:
hosts:
- host: "chart-example.local"
paths:
- path: /
service:
identifier: main
port: http
asserts:
- hasDocuments:
count: 4
- documentIndex: 0
not: true
isKind:
of: Ingress
- documentIndex: 1
not: true
isKind:
of: Ingress
- documentIndex: &FirstIngressDocument 2
isKind:
of: Ingress
- documentIndex: *FirstIngressDocument
equal:
path: metadata.name
value: RELEASE-NAME-main
- documentIndex: &SecondIngressDocument 3
isKind:
of: Ingress
- documentIndex: *SecondIngressDocument
equal:
path: metadata.name
value: RELEASE-NAME-test
- it: multiple ingress with explicit disabled should pass
values:
- ../_values/ingress_main_default_hosts.yaml
set:
ingress.test:
enabled: false
hosts:
- host: "chart-example.local"
paths:
- path: /
service:
identifier: main
port: http
asserts:
- hasDocuments:
count: 2
- documentIndex: 0
not: true
isKind:
of: Ingress
- documentIndex: &FirstIngressDocument 1
isKind:
of: Ingress
- documentIndex: *FirstIngressDocument
equal:
path: metadata.name
value: RELEASE-NAME

View file

@ -0,0 +1,143 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: ingress service reference
templates:
- common.yaml
values:
- ../_values/ingress_main_default_hosts.yaml
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
set:
service:
main:
controller: main
ports:
http:
port: &httpPort 8081
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].backend
value:
service:
name: RELEASE-NAME
port:
number: *httpPort
- it: custom service reference should pass
set:
ingress.main:
hosts:
- host: chart-test.local
paths:
- path: /
service:
name: pathService
port: 1234
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].backend
value:
service:
name: pathService
port:
number: 1234
- it: custom service reference with template should pass
set:
ingress.main:
hosts:
- host: chart-test.local
paths:
- path: /
service:
name: "{{ .Release.Name }}"
port: 1234
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].backend
value:
service:
name: RELEASE-NAME
port:
number: 1234
- it: multiple hosts with port name references should pass
set:
service:
main:
controller: main
ports:
http:
port: &httpPort 8081
http2:
enabled: true
port: &http2Port 1880
ingress:
main:
className: "nginx"
hosts:
- host: http.chart-test.local
paths:
- path: /
pathType: Prefix
service:
identifier: main
port: http
- host: http2.chart-test.local
paths:
- path: /
pathType: Prefix
service:
identifier: main
port: http2
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
# First Ingress host
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].host
value: http.chart-test.local
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].path
value: "/"
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].backend.service.name
value: "RELEASE-NAME"
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].backend.service.port.number
value: *httpPort
# Second Ingress host
- documentIndex: *IngressDocument
equal:
path: spec.rules[1].host
value: http2.chart-test.local
- documentIndex: *IngressDocument
equal:
path: spec.rules[1].http.paths[0].path
value: "/"
- documentIndex: *IngressDocument
equal:
path: spec.rules[1].http.paths[0].backend.service.name
value: "RELEASE-NAME"
- documentIndex: *IngressDocument
equal:
path: spec.rules[1].http.paths[0].backend.service.port.number
value: *http2Port

View file

@ -0,0 +1,90 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: ingress tls
templates:
- common.yaml
values:
- ../_values/ingress_main_default_hosts.yaml
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
notExists:
path: spec.tls
- it: tls enabled should pass
set:
ingress.main:
tls:
- secretName: test
hosts:
- hostname
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.tls[0]
value:
secretName: test
hosts:
- hostname
- it: tls enabled without secret should pass
set:
ingress.main:
tls:
- hosts:
- hostname
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.tls[0]
value:
hosts:
- hostname
- it: tls enabled with secret template should pass
set:
ingress.main:
tls:
- secretName: "{{ .Release.Name }}-secret"
hosts:
- hostname
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.tls[0]
value:
secretName: RELEASE-NAME-secret
hosts:
- hostname
- it: tls enabled with secret template evaluate empty should pass
set:
ingress.main:
tls:
- secretName: '{{ "" }}'
hosts:
- hostname
asserts:
- documentIndex: &IngressDocument 1
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.tls[0]
value:
hosts:
- hostname

View file

@ -0,0 +1,132 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: ingress values
templates:
- common.yaml
values:
- ../_values/ingress_main_default_hosts.yaml
- ../_values/service_main_default.yaml
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].host
value: chart-example.local
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].path
value: "/"
- it: nameOverride should pass
set:
ingress.main:
nameOverride: test
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: metadata.name
value: RELEASE-NAME-test
- it: nameOverride with template should pass
set:
ingress.main:
nameOverride: "{{ .Release.Name }}"
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: metadata.name
value: RELEASE-NAME
- it: custom host and path should pass
set:
ingress.main:
hosts:
- host: chart-test.local
paths:
- path: /test
service:
identifier: main
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].host
value: chart-test.local
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].path
value: "/test"
- it: host with template should pass
set:
ingress.main:
hosts:
- host: "{{ .Release.Name }}.hostname"
paths:
- path: /
service:
identifier: main
port: http
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].host
value: RELEASE-NAME.hostname
- it: path with template should pass
set:
ingress.main:
hosts:
- host: chart-test.local
paths:
- path: "/{{ .Release.Name }}.path"
service:
identifier: main
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.rules[0].http.paths[0].path
value: "/RELEASE-NAME.path"
- it: with defaultBackend should pass
set:
ingress.main:
defaultBackend:
resource:
apiGroup: k8s.example.com
kind: StorageBucket
name: static-assets
asserts:
- documentIndex: &IngressDocument 2
isKind:
of: Ingress
- documentIndex: *IngressDocument
equal:
path: spec.defaultBackend
value:
resource:
apiGroup: k8s.example.com
kind: StorageBucket
name: static-assets
- documentIndex: *IngressDocument
notExists:
path: spec.rules

View file

@ -0,0 +1,29 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: nameOverride tests
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default name is set to release name
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: metadata.name
value: RELEASE-NAME
- it: global.nameOverride can be set
set:
global.nameOverride: custom-name
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: metadata.name
value: RELEASE-NAME-custom-name

View file

@ -0,0 +1,94 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: networkPolicy metadata
set:
networkpolicies.main:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
notExists:
path: metadata.annotations
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
networkpolicies:
main:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
networkpolicies:
main:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,85 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: networkPolicy names
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
set:
networkpolicies:
main:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
asserts:
- hasDocuments:
count: 2
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.name
value: RELEASE-NAME
- it: custom name suffix should pass
set:
networkpolicies:
main:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
nameOverride: block-ingress
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: metadata.name
value: RELEASE-NAME-block-ingress
- it: multiple networkpolicies can be enabled
set:
networkpolicies:
primary:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
secondary:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
asserts:
- hasDocuments:
count: 3
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: &firstNetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *firstNetworkPolicyDocument
equal:
path: metadata.name
value: RELEASE-NAME-primary
- documentIndex: 2
isKind:
of: NetworkPolicy
- documentIndex: &secondNetworkPolicyDocument 2
isKind:
of: NetworkPolicy
- documentIndex: *secondNetworkPolicyDocument
equal:
path: metadata.name
value: RELEASE-NAME-secondary

View file

@ -0,0 +1,40 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: NetworkPolicy validations
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: networkpolicy requires either controller reference or podSelector
set:
networkpolicies:
main:
controller: ""
rules: {}
asserts:
- failedTemplate:
errorMessage: "controller reference or podSelector is required for NetworkPolicy. (NetworkPolicy main)"
- it: policyTypes is required
set:
networkpolicies:
main:
controller: main
policyTypes: []
rules: {}
asserts:
- failedTemplate:
errorMessage: "policyTypes is required for NetworkPolicy. (NetworkPolicy main)"
- it: policyTypes values check
set:
networkpolicies:
main:
controller: main
policyTypes:
- test
rules: {}
asserts:
- failedTemplate:
errorMessage: "Not a valid policyType for NetworkPolicy. (NetworkPolicy main, value test)"

View file

@ -0,0 +1,103 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: NetworkPolicy values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: main networkpolicy is disabled by default
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: NetworkPolicy
- it: main networkpolicy can be enabled
set:
networkpolicies.main:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
asserts:
- hasDocuments:
count: 2
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 1
isKind:
of: NetworkPolicy
- it: networkpolicy targets the correct controller
set:
networkpolicies:
main:
controller: main
policyTypes:
- Ingress
- Egress
rules: {}
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: spec.podSelector
value:
matchLabels:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME
- it: networkpolicy targets supports custom podSelector
set:
networkpolicies:
main:
controller: main
policyTypes:
- Ingress
- Egress
podSelector: {}
rules: {}
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: spec.podSelector
value: {}
- it: networkpolicy rules are passed through
set:
networkpolicies:
main:
controller: main
policyTypes:
- Ingress
- Egress
rules:
ingress:
- {}
egress:
- {}
asserts:
- documentIndex: &NetworkPolicyDocument 1
isKind:
of: NetworkPolicy
- documentIndex: *NetworkPolicyDocument
equal:
path: spec.ingress
value:
- {}
- documentIndex: *NetworkPolicyDocument
equal:
path: spec.egress
value:
- {}

View file

@ -0,0 +1,80 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence claimnames
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
set:
persistence:
config:
accessMode: ReadWriteOnce
size: 1Gi
asserts:
- documentIndex: 1
isKind:
of: Deployment
- documentIndex: 1
equal:
path: spec.template.spec.volumes[0]
value:
name: config
persistentVolumeClaim:
claimName: RELEASE-NAME-config
- it: with existingClaim should pass
set:
persistence:
existingClaim:
existingClaim: myClaim
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: existingClaim
persistentVolumeClaim:
claimName: myClaim
- it: disabled suffix should pass
set:
persistence:
claimWithoutSuffix:
nameOverride: "-"
accessMode: ReadWriteMany
size: 1G
asserts:
- documentIndex: 1
isKind:
of: Deployment
- documentIndex: 1
equal:
path: spec.template.spec.volumes[0]
value:
name: claimWithoutSuffix
persistentVolumeClaim:
claimName: RELEASE-NAME
- it: custom suffix should pass
set:
persistence:
claimWithNameOverride:
nameOverride: suffix
accessMode: ReadWriteMany
size: 1G
asserts:
- documentIndex: 1
isKind:
of: Deployment
- documentIndex: 1
equal:
path: spec.template.spec.volumes[0]
value:
name: claimWithNameOverride
persistentVolumeClaim:
claimName: RELEASE-NAME-suffix

View file

@ -0,0 +1,78 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence configmap
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: configmap persistence type should pass
set:
persistence:
configmap:
type: configMap
name: mySettings
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: configmap
configMap:
name: mySettings
- it: configmap persistence type with name template should pass
set:
persistence:
configmap:
type: configMap
name: '{{ include "bjw-s.common.lib.chart.names.fullname" $ }}-config'
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: configmap
configMap:
name: RELEASE-NAME-config
- it: configmap persistence type with identifier reference should pass
set:
configMaps:
mySettings:
data:
test: testvalue
persistence:
configmap:
type: configMap
identifier: mySettings
asserts:
- documentIndex: 0
isKind:
of: ConfigMap
- documentIndex: 1
isKind:
of: Deployment
- documentIndex: 1
equal:
path: spec.template.spec.volumes[0]
value:
name: configmap
configMap:
name: RELEASE-NAME-mySettings
- it: configmap persistence type with invalid identifier reference should fail
set:
persistence:
configmap:
type: configMap
identifier: doesNotExist
asserts:
- failedTemplate:
errorMessage: "No configmap found with this identifier. (persistence item 'configmap', identifier 'doesNotExist')"

View file

@ -0,0 +1,34 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence custom
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: custom persistence type should pass
set:
persistence:
custom-mount:
enabled: true
type: custom
volumeSpec:
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: custom-mount
downwardAPI:
items:
- fieldRef:
fieldPath: metadata.labels
path: labels

View file

@ -0,0 +1,64 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence emptydir
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default emptyDir should pass
set:
persistence:
config:
enabled: true
type: emptyDir
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: config
emptyDir: {}
- it: emptyDir with medium should pass
set:
persistence:
config:
enabled: true
type: emptyDir
medium: memory
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: config
emptyDir:
medium: memory
- it: emptyDir with medium and sizeLimit should pass
set:
persistence:
config:
enabled: true
type: emptyDir
medium: memory
sizeLimit: 1Gi
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: config
emptyDir:
medium: memory
sizeLimit: 1Gi

View file

@ -0,0 +1,47 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence hostpath
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: hostPath should pass
set:
persistence:
hostpathmounts-data:
enabled: true
type: hostPath
hostPath: "/tmp1"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: hostpathmounts-data
hostPath:
path: /tmp1
- it: hostPath with type should pass
set:
persistence:
hostpathmounts-with-type:
enabled: true
type: hostPath
hostPath: "/tmp2"
hostPathType: "Directory"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: hostpathmounts-with-type
hostPath:
path: /tmp2
type: Directory

View file

@ -0,0 +1,28 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence nfs
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: nfs persistence type should pass
set:
persistence:
nfs:
enabled: true
type: nfs
server: 10.10.0.8
path: /tank/nas/library
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: nfs
nfs:
path: /tank/nas/library
server: 10.10.0.8

View file

@ -0,0 +1,77 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence secret
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: secret persistence type should pass
set:
persistence:
secret:
enabled: true
type: secret
name: mySettings
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: secret
secret:
secretName: mySettings
- it: secret persistence type with name template should pass
set:
persistence:
secret:
enabled: true
type: secret
name: "{{ .Release.Name }}-config"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: secret
secret:
secretName: RELEASE-NAME-config
- it: secret persistence type with identifier reference should pass
set:
secrets:
mySettings:
stringData:
test: testvalue
persistence:
secret:
type: secret
identifier: mySettings
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.volumes[0]
value:
name: secret
secret:
secretName: RELEASE-NAME-mySettings
- it: secret persistence type with invalid identifier reference should fail
set:
persistence:
secret:
type: secret
identifier: doesNotExist
asserts:
- failedTemplate:
errorMessage: "No secret found with this identifier. (persistence item 'secret', identifier 'doesNotExist')"

View file

@ -0,0 +1,92 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence volumeclaimtemplates
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
set:
controllers.main:
type: statefulset
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
notExists:
path: spec.volumeClaimTemplates
- it: volumeClaimTemplates should pass
set:
controllers.main:
type: statefulset
statefulset:
volumeClaimTemplates:
- name: "storage"
size: "10Gi"
accessMode: "ReadWriteOnce"
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
equal:
path: spec.volumeClaimTemplates[0]
value:
metadata:
name: storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
- it: volumeClaimTemplates with dataSource should pass
set:
controllers.main:
type: statefulset
statefulset:
volumeClaimTemplates:
- name: "storage"
size: "10Gi"
accessMode: "ReadWriteOnce"
dataSource:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: MySnapshot
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
equal:
path: spec.volumeClaimTemplates[0].spec.dataSource
value:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: MySnapshot
- it: volumeClaimTemplates with templated dataSource name should pass
set:
controllers.main:
type: statefulset
statefulset:
volumeClaimTemplates:
- name: "storage"
size: "10Gi"
accessMode: "ReadWriteOnce"
dataSource:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: "{{ .Release.Name }}-config"
asserts:
- documentIndex: &StatefulSetDoc 0
isKind:
of: StatefulSet
- documentIndex: *StatefulSetDoc
equal:
path: spec.volumeClaimTemplates[0].spec.dataSource.name
value: RELEASE-NAME-config

View file

@ -0,0 +1,111 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistence volumes
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: no persistence should pass
asserts:
- documentIndex: &DeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
notExists:
path: spec.template.spec.volumes
- it: default should pass
set:
persistence:
config:
accessMode: ReadWriteOnce
size: 1Gi
asserts:
- documentIndex: &DeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *DeploymentDoc
equal:
path: spec.template.spec.volumes
value:
- name: config
persistentVolumeClaim:
claimName: RELEASE-NAME-config
- it: advanced mount config should pass
set:
controllers:
main:
containers:
second-container:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
second:
containers:
first-container:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
persistence:
config:
existingClaim: test
advancedMounts:
main:
main:
- path: /config
readOnly: false
data:
type: configMap
name: myConfigMap
globalMounts:
- path: /globalTest
advancedMounts:
main:
main:
- path: /data/config.yaml
readOnly: false
subPath: config.yaml
second-container:
- path: /appdata/config
readOnly: true
second:
first-container:
- path: /second-pod/config.yaml
readOnly: false
subPath: config.yaml
no-mounts:
existingClaim: test
asserts:
- documentIndex: &FirstDeploymentDoc 0
isKind:
of: Deployment
- documentIndex: *FirstDeploymentDoc
equal:
path: spec.template.spec.volumes
value:
- name: config
persistentVolumeClaim:
claimName: test
- configMap:
name: myConfigMap
name: data
- name: no-mounts
persistentVolumeClaim:
claimName: test
- documentIndex: &SecondDeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *SecondDeploymentDoc
equal:
path: spec.template.spec.volumes
value:
- configMap:
name: myConfigMap
name: data
- name: no-mounts
persistentVolumeClaim:
claimName: test

View file

@ -0,0 +1,111 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod with multiple containers
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: with explicit name should pass
set:
controllers.main.containers:
additional1:
nameOverride: template-test
dependsOn: main
image:
repository: test
tag: test
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[1].name
value: template-test
- it: with implicit name should pass
set:
controllers.main.containers:
additional1:
dependsOn: main
image:
repository: test
tag: test
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[1].name
value: additional1
- it: with templated name should pass
set:
controllers.main.containers:
additional1:
nameOverride: "{{ .Release.Name }}-container"
dependsOn: main
image:
repository: test
tag: test
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[1].name
value: RELEASE-NAME-container
- it: with custom env vars dict should pass
set:
controllers.main.containers:
main:
env:
main_env: value
additional1:
dependsOn: main
image:
repository: test
tag: test
env:
int: 1
float: 1.5
string: value_of_env
template: "{{ .Release.Name }}-admin"
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[0].env[0]
value:
name: main_env
value: "value"
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[1].env[0]
value:
name: float
value: "1.5"
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[1].env[1]
value:
name: int
value: "1"
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[1].env[2]
value:
name: string
value: value_of_env
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[1].env[3]
value:
name: template
value: RELEASE-NAME-admin

View file

@ -0,0 +1,86 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod sidecar containers
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: with default order
set:
controllers.main.containers:
main:
image:
repository: test
tag: test
additional1:
image:
repository: test
tag: test
additional2:
image:
repository: test
tag: test
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
lengthEqual:
path: spec.template.spec.containers
count: 3
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[0].name
value: additional1
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[1].name
value: additional2
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[2].name
value: main
- it: with dependsOn
set:
controllers.main.containers:
additional1:
dependsOn: additional3
image:
repository: test
tag: test
additional2:
dependsOn: additional3
image:
repository: test
tag: test
additional3:
dependsOn: main
image:
repository: test
tag: test
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
lengthEqual:
path: spec.template.spec.containers
count: 4
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[0].name
value: main
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[1].name
value: additional3
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[2].name
value: additional1
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.containers[3].name
value: additional2

View file

@ -0,0 +1,114 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod affinity
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: affinity is not present by default
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: spec.template.spec.affinity
- it: affinity can be set with defaultPodOption
set:
defaultPodOptions:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
- it: affinity can be set with defaultPodOption and overridden on pod level
set:
defaultPodOptions:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
controllers:
main:
pod:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- asia-east1
- asia-west1
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- asia-east1
- asia-west1
- it: affinity can be configured with templated valued
set:
controllers:
main:
pod:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- "{{ .Release.Name }}"
topologyKey: kubernetes.io/hostname
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- RELEASE-NAME
topologyKey: kubernetes.io/hostname

View file

@ -0,0 +1,61 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod dnsConfig
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.dnsConfig
- it: defaultPodOption should pass
set:
defaultPodOptions:
dnsConfig:
options:
- name: ndots
value: "1"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.dnsConfig
value:
options:
- name: ndots
value: "1"
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
dnsConfig:
options:
- name: ndots
value: "1"
controllers:
main:
pod:
dnsConfig:
options:
- name: ndots
value: "5"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.dnsConfig
value:
options:
- name: ndots
value: "5"

View file

@ -0,0 +1,43 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod dnsPolicy
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.dnsPolicy
value: ClusterFirst
- it: hostNetwork enabled should pass
set:
defaultPodOptions:
hostNetwork: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.dnsPolicy
value: ClusterFirstWithHostNet
- it: custom dnsPolicy should pass
set:
defaultPodOptions:
dnsPolicy: None
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.dnsPolicy
value: None

View file

@ -0,0 +1,41 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod enableServiceLinks
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.enableServiceLinks
value: false
- it: enabled in defaultPodOptions should pass
set:
defaultPodOptions.enableServiceLinks: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.enableServiceLinks
value: true
- it: enabled in pod options should pass
set:
controllers.main.pod.enableServiceLinks: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.enableServiceLinks
value: true

View file

@ -0,0 +1,64 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod hostAliases
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.hostAliases
- it: defaultPodOption should pass
set:
defaultPodOptions:
hostAliases:
- ip: "192.168.1.100"
hostnames:
- "example.com"
- "www.example.com"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostAliases
value:
- ip: "192.168.1.100"
hostnames:
- "example.com"
- "www.example.com"
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
hostAliases:
- ip: "192.168.1.100"
hostnames:
- "example.com"
- "www.example.com"
controllers:
main:
pod:
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "localhost"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostAliases
value:
- ip: "127.0.0.1"
hostnames:
- "localhost"

View file

@ -0,0 +1,43 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod security
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostIPC
value: false
- it: hostIPC disabled should pass
set:
defaultPodOptions:
hostIPC: false
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostIPC
value: false
- it: hostIPC enabled should pass
set:
defaultPodOptions:
hostIPC: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostIPC
value: true

View file

@ -0,0 +1,43 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod hostNetwork
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostNetwork
value: false
- it: hostNetwork disabled should pass
set:
defaultPodOptions:
hostNetwork: false
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostNetwork
value: false
- it: hostNetwork enabled should pass
set:
defaultPodOptions:
hostNetwork: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostNetwork
value: true

View file

@ -0,0 +1,43 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod security
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostPID
value: false
- it: hostPID disabled should pass
set:
defaultPodOptions:
hostPID: false
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostPID
value: false
- it: hostPID enabled should pass
set:
defaultPodOptions:
hostPID: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostPID
value: true

View file

@ -0,0 +1,59 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod security
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
capabilities:
majorVersion: 1
minorVersion: 29
tests:
- it: should not be present by default for kubernetes < 1.28
capabilities:
majorVersion: 1
minorVersion: 28
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: spec.template.spec.hostUsers
- it: should not be present even if specified for kubernetes < 1.28
capabilities:
majorVersion: 1
minorVersion: 28
set:
defaultPodOptions:
hostUsers: false
documentSelector: *DeploymentSelector
asserts:
- notExists:
path: spec.template.spec.hostUsers
- it: should not be present by default for kubernetes >= 1.29
documentSelector: *DeploymentSelector
asserts:
- notExists:
path: spec.template.spec.hostUsers
- it: hostUsers disabled should set for kubernetes >= 1.29
set:
defaultPodOptions:
hostUsers: false
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.hostUsers
value: false
- it: hostUsers enabled should be set for kubernetes >= 1.29
set:
defaultPodOptions:
hostUsers: true
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.hostUsers
value: true

View file

@ -0,0 +1,51 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod imagePullSecrets
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.imagePullSecrets
- it: defaultPodOption should pass
set:
defaultPodOptions:
imagePullSecrets:
- name: my-pull-secret
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.imagePullSecrets
value:
- name: my-pull-secret
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
imagePullSecrets:
- name: my-pull-secret
controllers:
main:
pod:
imagePullSecrets:
- name: my-other-secret
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.imagePullSecrets
value:
- name: my-other-secret

View file

@ -0,0 +1,51 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod nodeSelector
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.nodeSelector
- it: defaultPodOption should pass
set:
defaultPodOptions:
nodeSelector:
disktype: ssd
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.nodeSelector
value:
disktype: ssd
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
nodeSelector:
disktype: ssd
controllers:
main:
pod:
nodeSelector:
disktype: hdd
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.nodeSelector
value:
disktype: hdd

View file

@ -0,0 +1,40 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod replicas
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.replicas
value: 1
- it: nil should pass
set:
controllers.main.replicas: null
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.replicas
- it: custom replicas should pass
set:
controllers.main.replicas: 3
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.replicas
value: 3

View file

@ -0,0 +1,66 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod securityContext
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.securityContext
- it: defaultPodOption should pass
set:
defaultPodOptions:
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.securityContext
value:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
controllers:
main:
pod:
securityContext:
runAsUser: 568
runAsGroup: 568
fsGroup: 568
fsGroupChangePolicy: OnRootMismatch
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.securityContext
value:
runAsUser: 568
runAsGroup: 568
fsGroup: 568
fsGroupChangePolicy: OnRootMismatch

View file

@ -0,0 +1,174 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod serviceAccount
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 1
- documentIndex: &deploymentDocument 0
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: default
- it: default with flag should pass
set:
enforceServiceAccountCreation: true
asserts:
- hasDocuments:
count: 1
- documentIndex: &deploymentDocument 0
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: default
- it: with create, without name should pass
set:
serviceAccount:
create: true
asserts:
- hasDocuments:
count: 3
- documentIndex: &serviceAccountDocument 0
isKind:
of: ServiceAccount
- documentIndex: &deploymentDocument 1
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: RELEASE-NAME
- it: with create, with name should pass
set:
serviceAccount:
create: true
name: mySA
asserts:
- hasDocuments:
count: 3
- documentIndex: &serviceAccountDocument 0
isKind:
of: ServiceAccount
- documentIndex: &deploymentDocument 1
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: mySA
- it: without create, with name should pass
set:
serviceAccount:
create: false
name: &serviceAccountName mySA
asserts:
- hasDocuments:
count: 1
- documentIndex: &deploymentDocument 0
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *serviceAccountName
- it: without create, with name, with flag should pass
set:
enforceServiceAccountCreation: true
serviceAccount:
create: false
name: &serviceAccountName mySA
asserts:
- hasDocuments:
count: 1
- documentIndex: &deploymentDocument 0
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: default
- it: with extraServiceAccounts default should pass
set:
serviceAccount:
create: false
name: &serviceAccountName mySA
extraServiceAccounts:
mySA2:
create: false
mySA3:
create: true
asserts:
- hasDocuments:
count: 3
- documentIndex: &deploymentDocument 1
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *serviceAccountName
- it: with extraServiceAccounts identifier should pass
set:
controllers:
main:
serviceAccount:
identifier: mySA3
serviceAccount:
create: false
name: mySA
extraServiceAccounts:
mySA2:
create: false
mySA3:
create: true
asserts:
- hasDocuments:
count: 3
- documentIndex: &deploymentDocument 1
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: RELEASE-NAME-mySA3
- it: with extraServiceAccounts name should pass
set:
controllers:
main:
serviceAccount:
name: arbitrary-SA
serviceAccount:
create: false
name: mySA
extraServiceAccounts:
mySA2:
create: false
mySA3:
create: true
asserts:
- hasDocuments:
count: 3
- documentIndex: &deploymentDocument 1
isKind:
of: Deployment
- documentIndex: *deploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: arbitrary-SA

View file

@ -0,0 +1,35 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod security
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: shareProcessNamespace should not be present by default
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: spec.template.spec.shareProcessNamespace
- it: shareProcessNamespace disabled should pass
set:
defaultPodOptions:
shareProcessNamespace: false
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.shareProcessNamespace
value: false
- it: shareProcessNamespace enabled should pass
set:
defaultPodOptions:
shareProcessNamespace: true
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.shareProcessNamespace
value: true

View file

@ -0,0 +1,66 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod tolerations
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.tolerations
- it: defaultPodOption should pass
set:
defaultPodOptions:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.tolerations
value:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
controllers:
main:
pod:
tolerations:
- key: "master"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.tolerations
value:
- key: "master"
operator: "Equal"
value: "value1"
effect: "NoSchedule"

View file

@ -0,0 +1,76 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod topologySpreadConstraints
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.topologySpreadConstraints
- it: defaultPodOption should pass
set:
defaultPodOptions:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: foo
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: foo
- it: defaultPodOption with pod override should pass
set:
defaultPodOptions:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: foo
controllers:
main:
pod:
topologySpreadConstraints:
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: foo
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.topologySpreadConstraints
value:
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: foo

View file

@ -0,0 +1,118 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod initContainers
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: with custom env vars dict should pass
set:
controllers.main.initContainers:
init1:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: latest
env:
int: 1
float: 1.5
string: value_of_env
template: "{{ .Release.Name }}-admin"
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].env[0]
value:
name: float
value: "1.5"
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].env[1]
value:
name: int
value: "1"
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].env[2]
value:
name: string
value: value_of_env
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].env[3]
value:
name: template
value: RELEASE-NAME-admin
- it: disabled should pass
set:
controllers.main.initContainers:
init1:
enabled: false
image:
repository: ghcr.io/mendhak/http-https-echo
tag: test
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
notExists:
path: spec.template.spec.initContainers
- it: with dependsOn
set:
controllers.main.initContainers:
init1:
dependsOn: init2
image:
repository: ghcr.io/mendhak/http-https-echo
tag: latest
init2:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: latest
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
lengthEqual:
path: spec.template.spec.initContainers
count: 2
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].name
value: init2
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[1].name
value: init1
- it: with custom restartPolicy (sidecar)
set:
controllers.main.initContainers:
test:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: latest
restartPolicy: Always
asserts:
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
lengthEqual:
path: spec.template.spec.initContainers
count: 1
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].name
value: test
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.initContainers[0].restartPolicy
value: Always

View file

@ -0,0 +1,66 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: "pod metadata: annotations"
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default pod annotations
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: spec.template.metadata.annotations
- it: pod annotations from defaultPodOptions should be included
set:
defaultPodOptions:
annotations:
defaultPodOptionsAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
defaultPodOptionsAnnotation: test
- it: pod annotations from pod options should be included
set:
controllers:
main:
pod:
annotations:
podOptionsAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
podOptionsAnnotation: test
- it: pod annotations from global annotations should not be included by default
set:
global:
annotations:
globalAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isNotSubset:
path: spec.template.metadata.annotations
content:
globalAnnotation: test
- it: pod annotations from global annotations should be included when requested
set:
global:
propagateGlobalMetadataToPods: true
annotations:
globalAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
globalAnnotation: test

View file

@ -0,0 +1,70 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: "pod metadata: labels"
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default pod labels
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME
- it: pod labels from defaultPodOptions should be included
set:
defaultPodOptions:
labels:
defaultPodOptionsLabel: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.labels
content:
defaultPodOptionsLabel: test
- it: pod labels from pod options should be included
set:
controllers:
main:
pod:
labels:
podOptionsLabel: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.labels
content:
podOptionsLabel: test
- it: pod labels from global labels should not be included by default
set:
global:
labels:
globalLabel: test
documentSelector: *DeploymentSelector
asserts:
- isNotSubset:
path: spec.template.metadata.labels
content:
globalLabel: test
- it: pod labels from global labels should be included when requested
set:
global:
propagateGlobalMetadataToPods: true
labels:
globalLabel: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.labels
content:
globalLabel: test

View file

@ -0,0 +1,112 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pvc datasource
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
persistence.config:
accessMode: ReadWriteOnce
size: 1Gi
tests:
- it: default should pass
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.dataSource
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.dataSourceRef
- it: with dataSource should pass
set:
persistence.config:
dataSource:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: MySnapshot
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: spec.dataSource
value:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: MySnapshot
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.dataSourceRef
- it: templated dataSource name should pass
set:
persistence.config:
dataSource:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: "{{ .Release.Name }}-config"
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: spec.dataSource
value:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: RELEASE-NAME-config
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.dataSourceRef
- it: with dataSourceRef should pass
set:
persistence.config:
dataSourceRef:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: MySnapshot
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: spec.dataSourceRef
value:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: MySnapshot
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.dataSource
- it: templated dataSourceRef name should pass
set:
persistence.config:
dataSourceRef:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: "{{ .Release.Name }}-config"
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: spec.dataSourceRef
value:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: RELEASE-NAME-config
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.dataSource

View file

@ -0,0 +1,110 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pvc metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
persistence.config:
accessMode: ReadWriteOnce
size: 1Gi
tests:
- it: default should pass
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: metadata.annotations
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: retain enabled should pass
set:
persistence.config:
retain: true
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.annotations
value:
helm.sh/resource-policy: keep
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
persistence.config:
labels:
test_label: test
annotations:
test_annotation: test
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
persistence.config:
labels:
test_label: test
annotations:
test_annotation: test
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.annotations
value:
test_annotation: test
global_annotation: test
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,67 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pvc names
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
persistence.config:
accessMode: ReadWriteOnce
size: 1Gi
tests:
- it: disabled should pass
set:
persistence.config.enabled: false
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: PersistentVolumeClaim
- it: enabled should pass
set:
persistence.config.enabled: true
asserts:
- hasDocuments:
count: 2
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: 1
not: true
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.name
value: RELEASE-NAME-config
- it: without suffix should pass
set:
persistence.config:
nameOverride: "-"
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.name
value: RELEASE-NAME
- it: with custom suffix should pass
set:
persistence.config:
nameOverride: "custom"
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.name
value: RELEASE-NAME-custom

View file

@ -0,0 +1,47 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pvc storageclass
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
persistence.config:
accessMode: ReadWriteOnce
size: 1Gi
tests:
- it: default should pass
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
notExists:
path: spec.storageClassName
- it: custom should pass
set:
persistence.config:
storageClass: custom
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: spec.storageClassName
value: custom
- it: empty should pass
set:
persistence.config:
storageClass: "-"
asserts:
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: spec.storageClassName
value: ""

View file

@ -0,0 +1,56 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pvc values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default enabled should pass
set:
persistence.test:
type: persistentVolumeClaim
accessMode: ReadWriteOnce
size: 1Gi
asserts:
- hasDocuments:
count: 2
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.name
value: RELEASE-NAME-test
- it: explicit enabled should pass
set:
persistence.test:
enabled: true
type: persistentVolumeClaim
accessMode: ReadWriteOnce
size: 1Gi
asserts:
- hasDocuments:
count: 2
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: PersistentVolumeClaim
- documentIndex: *PersistentVolumeClaimDocument
equal:
path: metadata.name
value: RELEASE-NAME-test
- it: explicit disabled
set:
persistence.test:
enabled: false
type: persistentVolumeClaim
accessMode: ReadWriteOnce
size: 1Gi
asserts:
- hasDocuments:
count: 1
- documentIndex: &PersistentVolumeClaimDocument 0
isKind:
of: Deployment

View file

@ -0,0 +1,82 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: rawResource metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
rawResources:
config:
apiVersion: v1
kind: Endpoint
spec:
test: test
tests:
- it: default metadata should be present
documentSelector: &EndpointSelector
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME-config
asserts:
- notExists:
path: metadata.annotations
- equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata can be configured
set:
rawResources:
config:
annotations:
test_annotation: test
labels:
test_label: test
documentSelector: *EndpointSelector
asserts:
- equal:
path: metadata.annotations
value:
test_annotation: test
- equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: global metadata can be configured with local overrides
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
rawResources:
config:
annotations:
test_annotation: test
labels:
test_label: test
documentSelector: *EndpointSelector
asserts:
- equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,70 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: rawResource values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
rawResources:
endpoint:
apiVersion: v1
kind: Endpoint
spec:
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: "{{ .Release.Name }}"
port: 443
protocol: TCP
tests:
- it: raw resources can be configured
documentSelector: &EndpointSelector
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME-endpoint
asserts:
- equal:
path: subsets[0].addresses[0].ip
value: 127.0.0.1
- it: nameOverride can be configured
set:
rawResources.endpoint:
nameOverride: test
documentSelector:
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME-test
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME-test
- it: nameOverride with template should pass
set:
rawResources.endpoint:
nameOverride: "{{ .Release.Name }}"
documentSelector:
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME
- it: spec can render Helm template
set:
rawResources.endpoint:
spec:
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: "{{ .Release.Name }}"
port: 443
protocol: TCP
documentSelector: *EndpointSelector
asserts:
- equal:
path: subsets[0].ports[0].name
value: RELEASE-NAME

View file

@ -0,0 +1,60 @@
---
suite: rbac metadata
set:
serviceAccount:
name: test-sa
templates:
- common.yaml
values:
- ../_values/rbac_values.yaml
tests:
- it: default metadata should pass
asserts:
- hasDocuments:
count: 4
- documentIndex: &RoleDocument 2
isKind:
of: Role
- documentIndex: *RoleDocument
notExists:
path: metadata.annotations
- documentIndex: *RoleDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
rbac:
roles:
defaultRole:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 4
- documentIndex: &RoleDocument 2
isKind:
of: Role
- documentIndex: *RoleDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *RoleDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,58 @@
---
suite: rbac names
set:
serviceAccount:
name: test-sa
templates:
- common.yaml
values:
- ../_values/rbac_values.yaml
tests:
- it: default role and rolebinding names should pass
asserts:
- hasDocuments:
count: 4
- documentIndex: &RoleDocument 2
isKind:
of: Role
- documentIndex: *RoleDocument
equal:
path: metadata.name
value: RELEASE-NAME-defaultRole
- documentIndex: &BindingDocument 3
isKind:
of: RoleBinding
- documentIndex: *BindingDocument
equal:
path: metadata.name
value: RELEASE-NAME-defaultBinding
- it: custom role name should pass
set:
rbac:
roles:
defaultRole:
forceRename: customRole
bindings:
defaultBinding:
forceRename: customBinding
asserts:
- hasDocuments:
count: 4
- documentIndex: &RoleDocument 2
isKind:
of: Role
- documentIndex: &BindingDocument 3
isKind:
of: RoleBinding
- documentIndex: *RoleDocument
equal:
path: metadata.name
value: customRole
- documentIndex: *BindingDocument
equal:
path: metadata.name
value: customBinding

View file

@ -0,0 +1,44 @@
---
suite: rbac validations
set:
serviceAccount:
name: test-sa
templates:
- common.yaml
values:
- ../_values/rbac_values.yaml
tests:
- it: role type must be valid
set:
rbac:
roles:
invalidRole:
type: InvalidRole
rules: {}
asserts:
- failedTemplate:
errorMessage: "You selected: `InvalidRole`. Type must be one of:"
- it: role rules can't be empty
set:
rbac:
roles:
invalidRole:
type: Role
rules: []
asserts:
- failedTemplate:
errorMessage: "Rules can't be empty"
- it: roleBinding requires roleRef
set:
rbac:
bindings:
invalidBinding:
type: RoleBinding
roleRef: {}
asserts:
- failedTemplate:
errorMessage: "If not using identifier roleRef must have a `name` key"

View file

@ -0,0 +1,52 @@
---
suite: rbac values
set:
serviceAccount:
name: test-sa
templates:
- common.yaml
values:
- ../_values/rbac_values.yaml
tests:
- it: default role and rolebinding should pass
asserts:
- hasDocuments:
count: 4
- documentIndex: &RoleDocument 2
isKind:
of: Role
- documentIndex: *RoleDocument
equal:
path: rules[0].verbs
value: ["get", "list"]
- documentIndex: &BindingDocument 3
isKind:
of: RoleBinding
- documentIndex: *BindingDocument
equal:
path: subjects[0].name
value: "test-sa"
- it: custom role values should pass
set:
rbac:
roles:
customRole:
type: ClusterRole
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["get", "list", "watch"]
asserts:
- hasDocuments:
count: 5
- documentIndex: &RoleDocument 2
isKind:
of: ClusterRole
- documentIndex: *RoleDocument
equal:
path: rules[0].verbs
value: ["get", "list", "watch"]

View file

@ -0,0 +1,94 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: route metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
route.main:
parentRefs:
- name: test
namespace: test
asserts:
- documentIndex: &routeDocument 1
isKind:
of: HTTPRoute
- documentIndex: *routeDocument
notExists:
path: metadata.annotations
- documentIndex: *routeDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
route.main:
annotations:
test_annotation: test
labels:
test_label: test
parentRefs:
- name: test
namespace: test
asserts:
- documentIndex: &routeDocument 1
isKind:
of: HTTPRoute
- documentIndex: *routeDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *routeDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
route.main:
annotations:
test_annotation: test
labels:
test_label: test
parentRefs:
- name: test
namespace: test
asserts:
- documentIndex: &routeDocument 1
isKind:
of: HTTPRoute
- documentIndex: *routeDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *routeDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,70 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: route presence
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: HTTPRoute
- it: explicitly disabled should pass
set:
route.main.enabled: false
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: HTTPRoute
- it: explicitly enabled should pass
set:
route.main:
enabled: true
parentRefs:
- name: test
namespace: test
asserts:
- hasDocuments:
count: 2
- documentIndex: 0
not: true
isKind:
of: HTTPRoute
- documentIndex: 1
isKind:
of: HTTPRoute
- it: multiple enabled should pass
set:
route:
main:
parentRefs:
- name: main
namespace: main
test:
parentRefs:
- name: test
namespace: test
asserts:
- hasDocuments:
count: 3
- documentIndex: 0
not: true
isKind:
of: HTTPRoute
- documentIndex: 1
isKind:
of: HTTPRoute
- documentIndex: 2
isKind:
of: HTTPRoute

View file

@ -0,0 +1,114 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: route service reference
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- group: ""
kind: Service
name: RELEASE-NAME
namespace: NAMESPACE
port: 8080
weight: 1
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].backendRefs[0]
value:
group: ""
kind: Service
name: RELEASE-NAME
namespace: NAMESPACE
port: 8080
weight: 1
- it: custom service reference should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- group: test
name: pathService
port: 1234
namespace: serviceNamespace
weight: 123
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].backendRefs[0]
value:
group: test
kind: Service
name: pathService
namespace: serviceNamespace
port: 1234
weight: 123
- it: custom service reference with filter should fail
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- group: test
name: pathService
port: 1234
namespace: serviceNamespace
weight: 123
filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
asserts:
- failedTemplate:
errorMessage: "backend refs and request redirect filters cannot co-exist."
- it: custom service with filter should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].filters[0]
value:
type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
- documentIndex: *HTTPRouteDocument
notExists:
path: spec.rules[0].backendRefs[0]

View file

@ -0,0 +1,348 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: route values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: setting gateway should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.parentRefs[0].name
value: parentName
- documentIndex: *HTTPRouteDocument
equal:
path: spec.parentRefs[0].namespace
value: parentNamespace
- it: custom host and path should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
hostnames:
- chart-test.local
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.hostnames[0]
value: chart-test.local
- it: custom host with template
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
hostnames:
- "{{ .Release.Name }}.local"
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.hostnames[0]
value: RELEASE-NAME.local
- it: path matches should only be used for HTTPRoutes and GRPCRoutes
set:
route:
main:
kind: HTTPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
timeouts:
backendRequest: 30s
grpc:
kind: GRPCRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
tcp:
kind: TCPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
tls:
kind: TLSRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
udp:
kind: UDPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
asserts:
- documentIndex: &GRPCRouteDocument 1
isKind:
of: GRPCRoute
- documentIndex: *GRPCRouteDocument
equal:
path: spec.rules[0].matches
value:
- path:
type: PathPrefix
value: /test
- documentIndex: *GRPCRouteDocument
equal:
path: spec.rules[0].filters
value:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
- documentIndex: &HTTPRouteDocument 2
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].matches
value:
- path:
type: PathPrefix
value: /test
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].filters
value:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
- documentIndex: &TCPRouteDocument 3
isKind:
of: TCPRoute
- documentIndex: *TCPRouteDocument
notExists:
path: spec.rules[0].matches
- documentIndex: *TCPRouteDocument
notExists:
path: spec.rules[0].filters
- documentIndex: &TLSRouteDocument 4
isKind:
of: TLSRoute
- documentIndex: *TLSRouteDocument
notExists:
path: spec.rules[0].matches
- documentIndex: *TLSRouteDocument
notExists:
path: spec.rules[0].filters
- documentIndex: &UDPRouteDocument 5
isKind:
of: UDPRoute
- documentIndex: *UDPRouteDocument
notExists:
path: spec.rules[0].matches
- documentIndex: *UDPRouteDocument
notExists:
path: spec.rules[0].filters
- documentIndex: *UDPRouteDocument
notExists:
path: spec.rules[0].timeouts
- it: hostnames shouldn't be used for TCPRoutes and UDPRoutes
set:
route:
main:
enabled: true
kind: TCPRoute
hostnames:
- chart-test.local
parentRefs:
- name: parentName
namespace: parentNamespace
udp:
enabled: true
kind: UDPRoute
hostnames:
- chart-test.local
parentRefs:
- name: parentName
namespace: parentNamespace
asserts:
- documentIndex: &TCPRouteDocument 1
isKind:
of: TCPRoute
- documentIndex: *TCPRouteDocument
notExists:
path: spec.hostnames
- documentIndex: &UDPRouteDocument 2
isKind:
of: UDPRoute
- documentIndex: *UDPRouteDocument
notExists:
path: spec.hostnames
- it: sectionName in parentRefs should be optional
set:
route:
main:
enabled: true
parentRefs:
- name: parentName
namespace: parentNamespace
second:
enabled: true
parentRefs:
- name: parentName
namespace: parentNamespace
sectionName: parentSection
asserts:
- documentIndex: &HTTPRouteDocumentFirst 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocumentFirst
notExists:
path: spec.parentRefs[0].sectionName
- documentIndex: &HTTPRouteDocumentSecond 2
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocumentSecond
equal:
path: spec.parentRefs[0].sectionName
value: parentSection
- it: timeouts should only be used for HTTPRoutes
set:
route:
main:
enabled: true
kind: HTTPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
timeouts:
backendRequest: 30s
grpc:
enabled: true
kind: GRPCRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
matches:
- path:
type: PathPrefix
value: /test
timeouts:
backendRequest: 10s
asserts:
- documentIndex: &GRPCRouteDocument 1
isKind:
of: GRPCRoute
- documentIndex: *GRPCRouteDocument
notExists:
path: spec.rules[0].timeouts.backendRequest
- documentIndex: &HTTPRouteDocument 2
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].timeouts.backendRequest
value: 30s

View file

@ -0,0 +1,118 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: secret metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
secrets:
secret:
stringData:
test: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &SecretDocument 1
isKind:
of: Secret
- documentIndex: *SecretDocument
notExists:
path: metadata.annotations
- documentIndex: *SecretDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
secrets:
secret:
stringData:
test: test
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &SecretDocument 1
isKind:
of: Secret
- documentIndex: *SecretDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *SecretDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
secrets:
secret:
stringData:
test: test
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &SecretDocument 1
isKind:
of: Secret
- documentIndex: *SecretDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *SecretDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom secret type should pass
set:
secrets:
secret:
stringData:
test: test
type: &type kubernetes.io/service-account-token
asserts:
- hasDocuments:
count: 2
- documentIndex: &SecretDocument 1
isKind:
of: Secret
- documentIndex: *SecretDocument
equal:
path: type
value: *type

View file

@ -0,0 +1,93 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: secret names
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: Secret
- it: with disabled secret should pass
set:
secrets:
secret:
enabled: false
stringData:
test: test
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: Secret
- it: with multiple secrets should pass
set:
secrets:
secret:
enabled: true
stringData:
foo: bar
secondary:
enabled: true
stringData:
test: test
asserts:
- hasDocuments:
count: 3
- documentIndex: &FirstSecretDocument 1
isKind:
of: Secret
- documentIndex: *FirstSecretDocument
isNotNullOrEmpty:
path: metadata.name
- documentIndex: &SecondSecretDocument 2
isKind:
of: Secret
- documentIndex: *SecondSecretDocument
isNotNullOrEmpty:
path: metadata.name
- it: default name should pass
set:
secrets:
secret:
stringData:
test: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &SecretDocument 1
isKind:
of: Secret
- documentIndex: *SecretDocument
equal:
path: metadata.name
value: RELEASE-NAME-secret
- it: with nameOverride should pass
set:
secrets:
secret:
stringData:
test: test
nameOverride: http
asserts:
- hasDocuments:
count: 2
- documentIndex: &SecretDocument 1
isKind:
of: Secret
- documentIndex: *SecretDocument
equal:
path: metadata.name
value: RELEASE-NAME-http

View file

@ -0,0 +1,35 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: secret Pod metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata should pass
set:
secrets:
secret_1:
stringData:
test: value 1
secret_2: # default enabled
stringData:
test_1: value 1
test_2: value 2
test_not_in_checksum:
includeInChecksum: false
stringData:
test: value 1
test_disabled:
enabled: false
stringData:
test: value 1
asserts:
- documentIndex: &ControllerDoc 0
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: spec.template.metadata.annotations
value:
checksum/secrets: cd4e5076088172611ca1c43c659a275232d9eeb887acc20575ac141038b9aacb

View file

@ -0,0 +1,84 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default metadata
values:
- ../_values/service_main_default.yaml
documentSelector: &ServiceSelector
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: metadata.annotations
- equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata
values:
- ../_values/service_main_default.yaml
set:
service:
main:
annotations:
test_annotation: test
labels:
test_label: test
documentSelector: *ServiceSelector
asserts:
- equal:
path: metadata.annotations
value:
test_annotation: test
- equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata
values:
- ../_values/service_main_default.yaml
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
service:
main:
annotations:
test_annotation: test
labels:
test_label: test
documentSelector: *ServiceSelector
asserts:
- equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,64 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service names
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default name
values:
- ../_values/service_main_default.yaml
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME
- it: custom name suffix
values:
- ../_values/service_main_default.yaml
set:
service.main.nameOverride: http
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-http
asserts:
- exists:
path: metadata.name
- it: custom name suffix with template
values:
- ../_values/service_main_default.yaml
set:
service.main.nameOverride: "{{ .Chart.Name }}"
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-common-test
asserts:
- exists:
path: metadata.name
- it: multiple services
values:
- ../_values/service_main_default.yaml
set:
service:
second:
controller: main
ports:
ui:
port: 8082
asserts:
- documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-main
exists:
path: metadata.name
- documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-second
exists:
path: metadata.name

View file

@ -0,0 +1,96 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service protocols
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should render
values:
- ../_values/service_main_default.yaml
documentSelector: &ServiceSelector
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: spec.ports[0].protocol
value: TCP
- it: explicit TCP should render
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.http.protocol: TCP
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0].protocol
value: TCP
- it: explicit UDP should render
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.http.protocol: UDP
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0].protocol
value: UDP
- it: explicit HTTP should render
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.http.protocol: HTTP
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0].protocol
value: TCP
- notExists:
path: metadata.annotations
- it: explicit HTTPS should render
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.http.protocol: HTTPS
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0].protocol
value: TCP
- it: explicit appProtocol should render
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.http.appProtocol: kubernetes.io/h2c
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0].appProtocol
value: kubernetes.io/h2c
- it: mixed protocols can be configured on the same port number
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.udptest:
port: 8081
protocol: UDP
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports
value:
- name: http
port: 8081
protocol: TCP
targetPort: 8081
- name: udptest
port: 8081
protocol: UDP
targetPort: 8081

View file

@ -0,0 +1,64 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service ports
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default should pass
values:
- ../_values/service_main_default.yaml
documentSelector: &ServiceSelector
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: spec.ports[0]
value:
name: http
port: 8081
protocol: TCP
targetPort: 8081
- it: custom name should pass
values:
- ../_values/service_main_default.yaml
set:
service:
main:
ports:
http:
enabled: false
server:
enabled: true
port: 8080
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0]
value:
name: server
port: 8080
protocol: TCP
targetPort: 8080
- it: custom target port should pass
values:
- ../_values/service_main_default.yaml
set:
service:
main:
ports:
http:
enabled: true
targetPort: 80
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports[0]
value:
name: http
port: 8081
protocol: TCP
targetPort: 80

View file

@ -0,0 +1,16 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: Service validations
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: invalid controller reference should fail
set:
service:
main:
controller: other
asserts:
- failedTemplate:
errorMessage: "No enabled controller found with this identifier. (service: 'main', controller: 'other')"

View file

@ -0,0 +1,122 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: ports and services are enabled by default
set:
service:
second:
type: ClusterIP
controller: main
ports:
first:
port: 80
documentSelector: &ServiceSelector
path: kind
value: Service
asserts:
- containsDocument:
kind: Service
apiVersion: v1
name: RELEASE-NAME
- it: service not present when disabled
values:
- ../_values/service_main_default.yaml
set:
service:
main:
enabled: false
asserts:
- not: true
containsDocument:
kind: Service
apiVersion: v1
name: RELEASE-NAME
- it: externalTrafficPolicy can be configured for NodePort service
values:
- ../_values/service_main_default.yaml
set:
service:
main:
type: NodePort
externalTrafficPolicy: Local
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.externalTrafficPolicy
value: Local
- it: internalTrafficPolicy can be configured
values:
- ../_values/service_main_default.yaml
set:
service:
main:
internalTrafficPolicy: Local
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.internalTrafficPolicy
value: Local
- it: externalTrafficPolicy can be configured for LoadBalancer service
values:
- ../_values/service_main_default.yaml
set:
service:
main:
type: LoadBalancer
externalTrafficPolicy: Local
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.externalTrafficPolicy
value: Local
- it: allocateLoadBalancerNodePorts can be set to true
values:
- ../_values/service_main_default.yaml
set:
service:
main:
type: LoadBalancer
allocateLoadBalancerNodePorts: true
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.allocateLoadBalancerNodePorts
value: true
- it: allocateLoadBalancerNodePorts can be set to false
values:
- ../_values/service_main_default.yaml
set:
service:
main:
type: LoadBalancer
allocateLoadBalancerNodePorts: false
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.allocateLoadBalancerNodePorts
value: false
- it: externalName can be configured for ExternalName service
values:
- ../_values/service_main_default.yaml
set:
service:
main:
type: ExternalName
externalName: my.database.example.com
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.externalName
value: my.database.example.com

View file

@ -0,0 +1,256 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: serviceAccount values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: a serviceAccount is not created by default
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: ServiceAccount
- it: a serviceAccount is not created when disabled
set:
serviceAccount:
create: false
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
not: true
isKind:
of: ServiceAccount
- it: controller uses named ServiceAccount by default
set:
serviceAccount:
create: false
name: &ServiceAccountName test
asserts:
- hasDocuments:
count: 1
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *ServiceAccountName
- it: controller uses `default` ServiceAccount if flag is enabled
set:
enforceServiceAccountCreation: true
serviceAccount:
create: false
name: test
asserts:
- hasDocuments:
count: 1
- documentIndex: &DeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: default
- it: a serviceAccount and Secret are created when enabled
set:
serviceAccount:
create: true
asserts:
- hasDocuments:
count: 3
- documentIndex: &ServiceAccountDocument 0
isKind:
of: ServiceAccount
- documentIndex: &DeploymentDocument 1
isKind:
of: Deployment
- documentIndex: &SecretDocument 2
isKind:
of: Secret
- documentIndex: *ServiceAccountDocument
equal:
path: metadata.name
value: &ServiceAccountName RELEASE-NAME
- documentIndex: *ServiceAccountDocument
equal:
path: secrets
value:
- name: RELEASE-NAME-default-sa-token
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *ServiceAccountName
- documentIndex: *SecretDocument
equal:
path: metadata.annotations
value:
kubernetes.io/service-account.name: RELEASE-NAME
- it: a serviceAccount and Secret are created with custom name
set:
serviceAccount:
create: true
name: &ServiceAccountName myAccount
asserts:
- hasDocuments:
count: 3
- documentIndex: &ServiceAccountDocument 0
isKind:
of: ServiceAccount
- documentIndex: &DeploymentDocument 1
isKind:
of: Deployment
- documentIndex: &SecretDocument 2
isKind:
of: Secret
- documentIndex: *ServiceAccountDocument
equal:
path: metadata.name
value: *ServiceAccountName
- documentIndex: *ServiceAccountDocument
equal:
path: secrets
value:
- name: RELEASE-NAME-default-sa-token
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *ServiceAccountName
- documentIndex: *SecretDocument
equal:
path: metadata.annotations
value:
kubernetes.io/service-account.name: *ServiceAccountName
- it: multiple serviceAccounts and Secrets are created when enabled
set:
serviceAccount:
create: true
name: &ServiceAccountName myAccount
extraServiceAccounts:
mySA:
create: true
asserts:
- hasDocuments:
count: 5
- documentIndex: &ServiceAccountDocument 0
isKind:
of: ServiceAccount
- documentIndex: &ServiceAccountDocument2 1
isKind:
of: ServiceAccount
- documentIndex: &DeploymentDocument 2
isKind:
of: Deployment
- documentIndex: &SecretDocument 3
isKind:
of: Secret
- documentIndex: &SecretDocument2 4
isKind:
of: Secret
- documentIndex: *ServiceAccountDocument
equal:
path: metadata.name
value: *ServiceAccountName
- documentIndex: *ServiceAccountDocument2
equal:
path: metadata.name
value: RELEASE-NAME-mySA
- documentIndex: *ServiceAccountDocument
equal:
path: secrets
value:
- name: RELEASE-NAME-default-sa-token
- documentIndex: *ServiceAccountDocument2
equal:
path: secrets
value:
- name: RELEASE-NAME-mySA-sa-token
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *ServiceAccountName
- documentIndex: *SecretDocument
equal:
path: metadata.annotations
value:
kubernetes.io/service-account.name: *ServiceAccountName
- documentIndex: *SecretDocument2
equal:
path: metadata.annotations
value:
kubernetes.io/service-account.name: RELEASE-NAME-mySA
- it: multiple serviceAccounts and Secrets are created with custom names
set:
serviceAccount:
create: true
name: &ServiceAccountName myAccount
extraServiceAccounts:
mySA:
create: true
name: &ServiceAccountName2 mySAcustom
mySA2:
create: false
name: &ServiceAccountName3 mySAcustom2
asserts:
- hasDocuments:
count: 5
- documentIndex: &ServiceAccountDocument 0
isKind:
of: ServiceAccount
- documentIndex: &ServiceAccountDocument2 1
isKind:
of: ServiceAccount
- documentIndex: &DeploymentDocument 2
isKind:
of: Deployment
- documentIndex: &SecretDocument 3
isKind:
of: Secret
- documentIndex: &SecretDocument2 4
isKind:
of: Secret
- documentIndex: *ServiceAccountDocument
equal:
path: metadata.name
value: *ServiceAccountName
- documentIndex: *ServiceAccountDocument2
equal:
path: metadata.name
value: *ServiceAccountName2
- documentIndex: *ServiceAccountDocument
equal:
path: secrets
value:
- name: RELEASE-NAME-default-sa-token
- documentIndex: *ServiceAccountDocument2
equal:
path: secrets
value:
- name: RELEASE-NAME-mySA-sa-token
- documentIndex: *DeploymentDocument
equal:
path: spec.template.spec.serviceAccountName
value: *ServiceAccountName
- documentIndex: *SecretDocument
equal:
path: metadata.annotations
value:
kubernetes.io/service-account.name: *ServiceAccountName
- documentIndex: *SecretDocument2
equal:
path: metadata.annotations
value:
kubernetes.io/service-account.name: *ServiceAccountName2

Some files were not shown because too many files have changed in this diff Show more