Skip to content

Commit

Permalink
chore: reorganize unit tests and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
eshepelyuk committed Nov 20, 2023
1 parent 30ba8ac commit d8e260e
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 399 deletions.
18 changes: 12 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ export E2E_TEST := "default"
default:
@just --list

test-lint:
./test/linter/test.sh
_helm-unittest:
helm plugin ls | grep unittest || helm plugin install https://github.com/helm-unittest/helm-unittest.git

test-unit:
helm plugin ls | grep unittest || helm plugin install https://github.com/helm-unittest/helm-unittest.git
helm unittest -f 'test/unit/*.yaml' .
# run helm unit tests
test-helm filter="*": _helm-unittest
helm unittest -f 'test/unit/{{filter}}.yaml' .

test: test-lint test-unit
test: lint test-helm

# helm linter
lint-helm filter="*": _helm-unittest
helm unittest -f 'test/lint/{{filter}}.yaml' .

lint: lint-helm

_skaffold-ctx:
skaffold config set default-repo localhost:5000
Expand Down
44 changes: 44 additions & 0 deletions test/lint/registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
suite: lint registry values
templates:
- fake.yaml
tests:
- it: nodeSelector is not object
set:
registry:
nodeSelector: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- registry.nodeSelector: Invalid type. Expected: object, given: string
- it: initContainers is not array
set:
registry:
initContainers: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- registry.initContainers: Invalid type. Expected: array, given: string
- it: extraVolumes is not array
set:
registry:
extraVolumes: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- registry.extraVolumes: Invalid type. Expected: array, given: string
- it: extraVolumeMounts is not array
set:
registry:
extraVolumeMounts: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- registry.extraVolumeMounts: Invalid type. Expected: array, given: string
44 changes: 44 additions & 0 deletions test/lint/sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
suite: lint sync values
templates:
- fake.yaml
tests:
- it: nodeSelector is not object
set:
sync:
nodeSelector: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- sync.nodeSelector: Invalid type. Expected: object, given: string
- it: initContainers is not array
set:
sync:
initContainers: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- sync.initContainers: Invalid type. Expected: array, given: string
- it: extraVolumes is not array
set:
sync:
extraVolumes: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- sync.extraVolumes: Invalid type. Expected: array, given: string
- it: extraVolumeMounts is not array
set:
sync:
extraVolumeMounts: "qwe"
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
apicurio-registry:
- sync.extraVolumeMounts: Invalid type. Expected: array, given: string
150 changes: 0 additions & 150 deletions test/linter/test.sh

This file was deleted.

111 changes: 111 additions & 0 deletions test/unit/deployment_registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
suite: test deployment-registry.yaml template
templates:
- deployment-registry.yaml
tests:
- it: no selector
asserts:
- notExists:
path: spec.template.spec.containers[0].nodeSelector
- it: with node selectors
set:
registry:
nodeSelector:
foo: bar
asserts:
- equal:
path: spec.template.spec.containers[0].nodeSelector.foo
value: bar
- it: no volumes
asserts:
- notExists:
path: spec.template.spec.volumes
- it: volumes
set:
registry:
extraVolumes:
- name: baz
emptyDir: {}
- name: foo
secret:
secretName: bar
optional: false
asserts:
- exists:
path: spec.template.spec.volumes
- equal:
path: spec.template.spec.volumes[0].name
value: baz
- equal:
path: spec.template.spec.volumes[0].emptyDir
value: {}
- equal:
path: spec.template.spec.volumes[1].name
value: foo
- equal:
path: spec.template.spec.volumes[1].secret.secretName
value: bar
- equal:
path: spec.template.spec.volumes[1].secret.optional
value: false
- it: no volume mounts
asserts:
- notExists:
path: spec.template.spec.containers[0].volumeMounts
- it: volume mounts
set:
registry:
extraVolumeMounts:
- name: foo
mountPath: /bar
readOnly: true
asserts:
- exists:
path: spec.template.spec.containers[0].volumeMounts
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].name
value: foo
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].mountPath
value: /bar
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].readOnly
value: true
- it: empty init container
asserts:
- notExists:
path: spec.template.spec.initContainers
- it: dummy init container
set:
registry:
initContainers:
- name: hello-world
image: dummy
command:
- /bin/sh
- -c
- echo "hello world"
volumeMounts:
- name: foo
mountPath: /bar
env:
- name: ENV_VAR
value: VALUE
asserts:
- equal:
path: spec.template.spec.initContainers[0].name
value: hello-world
- equal:
path: spec.template.spec.initContainers[0].command
value: [/bin/sh, -c, echo "hello world"]
- equal:
path: spec.template.spec.initContainers[0].volumeMounts[0].name
value: foo
- equal:
path: spec.template.spec.initContainers[0].volumeMounts[0].mountPath
value: /bar
- equal:
path: spec.template.spec.initContainers[0].env[0].name
value: ENV_VAR
- equal:
path: spec.template.spec.initContainers[0].env[0].value
value: VALUE
Loading

0 comments on commit d8e260e

Please sign in to comment.