add tests

This commit is contained in:
Stavros kois
2023-12-08 02:08:39 +02:00
parent 88d7a96f45
commit 2e203f8eb9
4 changed files with 579 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
suite: certificate data test
templates:
- common.yaml
chart:
appVersion: &appVer v9.9.9
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should pass with certificate created
set:
issuer: some-issuer
host: host1
certificate:
my-certificate1:
enabled: true
hosts:
- "{{ .Values.host }}"
certificateIssuer: "{{ .Values.issuer }}"
my-certificate2:
enabled: true
hosts:
- host2
certificateIssuer: some-other-issuer
certificateSecretTemplate:
labels:
label1: label1
label2: label2
annotations:
annotation1: annotation1
annotation2: annotation2
asserts:
- documentIndex: &certDoc 0
isKind:
of: Certificate
- documentIndex: *certDoc
isAPIVersion:
of: cert-manager.io/v1
- documentIndex: *certDoc
equal:
path: metadata.name
value: test-release-name-common-test-my-certificate1
- documentIndex: *certDoc
equal:
path: metadata.namespace
value: test-release-namespace
- documentIndex: *certDoc
equal:
path: spec
value:
secretName: test-release-name-common-test-my-certificate1
dnsNames:
- host1
issuerRef:
name: some-issuer
kind: ClusterIssuer
group: cert-manager.io
privateKey:
algorithm: ECDSA
size: 256
rotationPolicy: Always
- documentIndex: &otherCertDoc 1
isKind:
of: Certificate
- documentIndex: *otherCertDoc
isAPIVersion:
of: cert-manager.io/v1
- documentIndex: *otherCertDoc
equal:
path: spec
value:
secretName: certificate-issuer-my-certificate2
dnsNames:
- host2
issuerRef:
name: some-other-issuer
kind: ClusterIssuer
group: cert-manager.io
privateKey:
algorithm: ECDSA
size: 256
rotationPolicy: Always
secretTemplate:
labels:
label1: label1
label2: label2
app: common-test-1.0.0
app.kubernetes.io/instance: test-release-name
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: common-test
app.kubernetes.io/version: v9.9.9
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
release: test-release-name
annotations:
annotation1: annotation1
annotation2: annotation2
- documentIndex: *otherCertDoc
equal:
path: metadata.name
value: certificate-issuer-my-certificate2
- documentIndex: *otherCertDoc
equal:
path: metadata.namespace
value: test-release-namespace

View File

@@ -0,0 +1,225 @@
suite: certificate metadata test
templates:
- common.yaml
chart:
appVersion: &appVer v9.9.9
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should pass with certificate created with labels and annotations
set:
label1: label1
label2: global_label2
label3: label3
annotation1: annotation1
annotation2: global_annotation2
annotation3: annotation3
global:
labels:
g_label1: global_label1
g_label2: "{{ .Values.label2 }}"
annotations:
g_annotation1: global_annotation1
g_annotation2: "{{ .Values.annotation2 }}"
certificate:
my-certificate1:
enabled: true
annotations:
annotation1: "{{ .Values.annotation1 }}"
annotation2: annotation2
labels:
label1: "{{ .Values.label1 }}"
label2: label2
hosts:
- host1
certificateIssuer: some-issuer
my-certificate2:
enabled: true
annotations:
annotation1: "{{ .Values.annotation1 }}"
annotation2: annotation2
labels:
label1: "{{ .Values.label1 }}"
label2: label2
hosts:
- host1
certificateIssuer: some-issuer
certificateSecretTemplate:
labels:
label3: "{{ .Values.label3 }}"
label4: label4
annotations:
annotation3: "{{ .Values.annotation3 }}"
annotation4: annotation4
asserts:
- documentIndex: &certDoc 0
isKind:
of: Certificate
- documentIndex: *certDoc
isAPIVersion:
of: cert-manager.io/v1
- documentIndex: *certDoc
equal:
path: metadata.annotations
value:
annotation1: annotation1
annotation2: annotation2
g_annotation1: global_annotation1
g_annotation2: global_annotation2
- documentIndex: *certDoc
equal:
path: metadata.labels
value:
app: common-test-1.0.0
release: test-release-name
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: *appVer
app.kubernetes.io/instance: test-release-name
app.kubernetes.io/name: common-test
g_label1: global_label1
g_label2: global_label2
label1: label1
label2: label2
- documentIndex: *certDoc
equal:
path: metadata.name
value: test-release-name-common-test-my-certificate1
- documentIndex: *certDoc
equal:
path: metadata.namespace
value: test-release-namespace
- documentIndex: &otherCertDoc 1
isKind:
of: Certificate
- documentIndex: *otherCertDoc
isAPIVersion:
of: cert-manager.io/v1
- documentIndex: *otherCertDoc
equal:
path: metadata.annotations
value:
annotation1: annotation1
annotation2: annotation2
g_annotation1: global_annotation1
g_annotation2: global_annotation2
- documentIndex: *otherCertDoc
equal:
path: metadata.labels
value:
app: common-test-1.0.0
release: test-release-name
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: *appVer
app.kubernetes.io/instance: test-release-name
app.kubernetes.io/name: common-test
g_label1: global_label1
g_label2: global_label2
label1: label1
label2: label2
- documentIndex: *otherCertDoc
equal:
path: metadata.name
value: certificate-issuer-my-certificate2
- documentIndex: *otherCertDoc
equal:
path: metadata.namespace
value: test-release-namespace
- documentIndex: *otherCertDoc
equal:
path: spec.secretTemplate.annotations
value:
annotation3: annotation3
annotation4: annotation4
g_annotation1: global_annotation1
g_annotation2: global_annotation2
- documentIndex: *otherCertDoc
equal:
path: spec.secretTemplate.labels
value:
app: common-test-1.0.0
release: test-release-name
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: *appVer
app.kubernetes.io/instance: test-release-name
app.kubernetes.io/name: common-test
g_label1: global_label1
g_label2: global_label2
label3: label3
label4: label4
- it: should pass with certificate created with namespace from tpl
set:
key: some-namespace
certificate:
my-cert1:
enabled: true
namespace: "{{ .Values.key }}"
hosts:
- host1
certificateIssuer: some-issuer
asserts:
- documentIndex: *certDoc
equal:
path: metadata.namespace
value: some-namespace
- it: should pass with certificate created with global namespace from tpl
set:
key: global-namespace
global:
namespace: "{{ .Values.key }}"
certificate:
my-cert1:
enabled: true
hosts:
- host1
certificateIssuer: some-issuer
asserts:
- documentIndex: *certDoc
equal:
path: metadata.namespace
value: global-namespace
- it: should pass with certificate created with root namespace from tpl
set:
key: local-namespace
namespace: "{{ .Values.key }}"
global:
namespace: global-namespace
certificate:
my-cert1:
enabled: true
hosts:
- host1
certificateIssuer: some-issuer
asserts:
- documentIndex: *certDoc
equal:
path: metadata.namespace
value: local-namespace
- it: should pass with certificate created with namespace in TrueNAS SCALE
set:
global:
ixChartContext:
iAmNotEmpty: true
namespace: ix-namespace
certificate:
my-cert1:
enabled: true
hosts:
- host1
certificateIssuer: some-issuer
asserts:
- documentIndex: *certDoc
equal:
path: metadata.namespace
value: ix-namespace

View File

@@ -0,0 +1,46 @@
suite: certificate name test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should generate correct name
set:
certificate:
my-cert1:
enabled: true
hosts:
- host1
certificateIssuer: some-issuer
my-cert2:
enabled: true
hosts:
- host1
certificateIssuer: some-issuer
certificateSecretTemplate:
labels:
some-label: my-cert2
annotations:
some-annotation: my-cert2
asserts:
- documentIndex: &certDoc 0
isKind:
of: Certificate
- documentIndex: *certDoc
isAPIVersion:
of: cert-manager.io/v1
- documentIndex: *certDoc
equal:
path: metadata.name
value: test-release-name-common-test-my-cert1
- documentIndex: &otherCertDoc 1
isKind:
of: Certificate
- documentIndex: *otherCertDoc
isAPIVersion:
of: cert-manager.io/v1
- documentIndex: *otherCertDoc
equal:
path: metadata.name
value: certificate-issuer-my-cert2

View File

@@ -0,0 +1,203 @@
suite: certificate validation test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should fail with name longer than 253 characters
set:
certificate:
my-certificate-super-long-name-that-is-longer-than-253-characters-my-certificate-super-long-name-that-is-longer-than-253-characters-my-certificate-super-long-name-that-is-longer-than-253-characters-my-certificate-super-long-long-long-long-long-long-long-long-name:
enabled: true
asserts:
- failedTemplate:
errorMessage: Name [test-release-name-common-test-my-certificate-super-long-name-that-is-longer-than-253-characters-my-certificate-super-long-name-that-is-longer-than-253-characters-my-certificate-super-long-name-that-is-longer-than-253-characters-my-certificate-super-long-long-long-long-long-long-long-long-name] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 253 characters.
- it: should fail with name starting with underscore
set:
certificate:
_my-cert:
enabled: true
asserts:
- failedTemplate:
errorMessage: Name [test-release-name-common-test-_my-cert] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 253 characters.
- it: should fail with namespace longer than 63 characters
set:
certificate:
my-certificate:
enabled: true
namespace: my-extra-super-duper-long-name-that-is-longer-than-63-characters
certificateIssuer: some-issuer
hosts:
- test-host
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Namespace [my-extra-super-duper-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.
- it: should fail with namespace not starting with [ix-] in TrueNAS SCALE
set:
global:
ixChartContext:
iAmNotEmpty: true
certificate:
my-certificate:
enabled: true
namespace: my-namespace
certificateIssuer: some-issuer
hosts:
- test-host
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Namespace [my-namespace] expected to have [ix-] prefix when installed in TrueNAS SCALE
- it: should fail with labels not a dict
set:
certificate:
my-cert:
enabled: true
labels: "not a dict"
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected [labels] to be a dictionary, but got [string]
- it: should fail with annotations not a dict
set:
certificate:
my-certificate:
enabled: true
annotations: "not a dict"
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected [annotations] to be a dictionary, but got [string]
- it: should fail with empty enabled
set:
certificate:
my-certificate:
enabled:
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected the defined key [enabled] in [certificate.my-certificate] to not be empty
- it: should fail if certificateIssuer is missing
set:
certificate:
my-cert:
enabled: true
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected non-empty [certificateIssuer]
- it: should fail if hosts are empty
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts: []
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected non-empty [hosts]
- it: should fail if hosts is not slice
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts: not-a-slice
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected [hosts] to be a [slice], but got [string]
- it: should fail if hosts entry is empty
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- ""
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected non-empty entry in [hosts]
- it: should fail if hosts entry starts with https://
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- https://test-host
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected entry in [hosts] to not start with [https://], but got [https://test-host]
- it: should fail if hosts entry starts with http://
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- http://test-host
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected entry in [hosts] to not start with [http://], but got [http://test-host]
- it: should fail if hosts entry contains ":"
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- test-host:123
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected entry in [hosts] to not contain [:], but got [test-host:123]
- it: should fail if certificateSecretTemplate missing both labels and annotations
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- test-host
certificateSecretTemplate:
some-key: some-value
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate - Expected [certificateSecretTemplate] to have at least one of [labels, annotations]
- it: should fail if certificateSecretTemplate labels are not a map
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- test-host
certificateSecretTemplate:
labels: "not a map"
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate (certificateSecretTemplate) - Expected [labels] to be a dictionary, but got [string]
- it: should fail if certificateSecretTemplate annotations are not a map
set:
certificate:
my-cert:
enabled: true
certificateIssuer: some-issuer
hosts:
- test-host
certificateSecretTemplate:
annotations: "not a map"
asserts:
- failedTemplate:
errorMessage: Cert Manager Certificate (certificateSecretTemplate) - Expected [annotations] to be a dictionary, but got [string]