diff --git a/library/common-test/tests/pod/deployment_annotation_test.yaml b/library/common-test/tests/pod/deployment_annotation_test.yaml new file mode 100644 index 00000000..da9a3632 --- /dev/null +++ b/library/common-test/tests/pod/deployment_annotation_test.yaml @@ -0,0 +1,57 @@ +suite: deployment annotation test +templates: + - common.yaml +tests: + - it: should pass with default values + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - isNotEmpty: + documentIndex: *deploymentDoc + path: metadata.annotations.rollme + + - it: should pass with controller and global annotations + set: + some_key: some_value + controller.annotations: + controller_key: controller_value + controller_key2: "{{ .Values.some_key }}" + global.annotations: + global_key: global_value + global_key2: "{{ .Values.some_key }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: metadata.annotations.controller_key + value: controller_value + - equal: + documentIndex: *deploymentDoc + path: metadata.annotations.controller_key2 + value: some_value + - equal: + documentIndex: *deploymentDoc + path: metadata.annotations.global_key + value: global_value + - equal: + documentIndex: *deploymentDoc + path: metadata.annotations.global_key2 + value: some_value + - isNotEmpty: + documentIndex: *deploymentDoc + path: metadata.annotations.rollme + + - it: should pass with podAnnotations set + set: + some_key: some_value2 + podAnnotations.test: some_value + podAnnotations.test2: "{{ .Values.some_key }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.metadata.annotations.test2 + value: some_value2 + - equal: + documentIndex: *deploymentDoc + path: spec.template.metadata.annotations.test + value: some_value diff --git a/library/common-test/tests/pod/deployment_controller_test.yaml b/library/common-test/tests/pod/deployment_controller_test.yaml new file mode 100644 index 00000000..20691d7d --- /dev/null +++ b/library/common-test/tests/pod/deployment_controller_test.yaml @@ -0,0 +1,78 @@ +suite: deployment controller test +templates: + - common.yaml +tests: + - it: should pass with default values + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - equal: + documentIndex: *deploymentDoc + path: apiVersion + value: apps/v1 + - equal: + documentIndex: *deploymentDoc + path: spec.revisionHistoryLimit + value: 3 + - equal: + documentIndex: *deploymentDoc + path: spec.replicas + value: 1 + - equal: + documentIndex: *deploymentDoc + path: spec.strategy.type + value: Recreate + - isNull: + documentIndex: *deploymentDoc + path: spec.strategy.rollingUpdate + + - it: should pass with controller strategy changed and rollingUpdate strategies set + set: + controller.strategy: RollingUpdate + controller.rollingUpdate.unavailable: 2 + controller.rollingUpdate.surge: 3 + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.strategy.type + value: RollingUpdate + - equal: + documentIndex: *deploymentDoc + path: spec.strategy.rollingUpdate + value: + maxUnavailable: 2 + maxSurge: 3 + + - it: should pass with controller disabled + set: + controller.enabled: false + asserts: + - hasDocuments: + count: 0 + + - it: should pass with controller strategy changed + set: + controller.strategy: RollingUpdate + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.strategy.type + value: RollingUpdate + - isNull: + documentIndex: *deploymentDoc + path: spec.strategy.rollingUpdate + + - it: should fail with wrong controller + set: + controller.type: not_valid_controller + asserts: + - failedTemplate: + errorMessage: Not a valid controller.type (not_valid_controller) + + - it: should fail with wrong strategy + set: + controller.strategy: not_valid_strategy + asserts: + - failedTemplate: + errorMessage: Not a valid strategy type for Deployment (not_valid_strategy) diff --git a/library/common-test/tests/pod/deployment_label_test.yaml b/library/common-test/tests/pod/deployment_label_test.yaml new file mode 100644 index 00000000..b87e194b --- /dev/null +++ b/library/common-test/tests/pod/deployment_label_test.yaml @@ -0,0 +1,71 @@ +suite: deployment label test +templates: + - common.yaml +tests: + - it: should pass with default values + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - equal: + documentIndex: *deploymentDoc + path: metadata.labels + value: + app: common-test + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: common-test + app.kubernetes.io/version: v1.0.0 + helm-revision: "0" + helm.sh/chart: common-test-1.0.0 + release: RELEASE-NAME + - equal: + documentIndex: *deploymentDoc + path: spec.selector.matchLabels + value: + app: common-test + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: common-test + release: RELEASE-NAME + + - it: should pass with controller and global labels + set: + some_key: some_value + controller.labels: + controller_key: controller_value + controller_key2: "{{ .Values.some_key }}" + global.labels: + global_key: global_value + global_key2: "{{ .Values.some_key }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: metadata.labels + value: + controller_key: controller_value + controller_key2: some_value + global_key: global_value + global_key2: some_value + app: common-test + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: common-test + app.kubernetes.io/version: v1.0.0 + helm-revision: "0" + helm.sh/chart: common-test-1.0.0 + release: RELEASE-NAME + + - it: should pass with podLabels set + set: + some_key: some_value2 + podLabels.test: some_value + podLabels.test2: "{{ .Values.some_key }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.metadata.labels.test2 + value: some_value2 + - equal: + documentIndex: *deploymentDoc + path: spec.template.metadata.labels.test + value: some_value diff --git a/library/common-test/tests/pod/deployment_names_test.yaml b/library/common-test/tests/pod/deployment_names_test.yaml new file mode 100644 index 00000000..ae03ee0e --- /dev/null +++ b/library/common-test/tests/pod/deployment_names_test.yaml @@ -0,0 +1,32 @@ +suite: deployment name test +templates: + - common.yaml +tests: + - it: should pass with default values + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - equal: + documentIndex: *deploymentDoc + path: metadata.name + value: RELEASE-NAME-common-test + + - it: should pass with nameOverride + set: + nameOverride: overrodeName + asserts: + - equal: + documentIndex: *deploymentDoc + path: metadata.name + value: RELEASE-NAME-overrodeName + + - it: should pass with global.nameOverride + set: + nameOverride: overrodeName + global.nameOverride: globalOverrodeName + asserts: + - equal: + documentIndex: *deploymentDoc + path: metadata.name + value: RELEASE-NAME-globalOverrodeName diff --git a/library/common-test/tests/pod/deployment_port_test.yaml b/library/common-test/tests/pod/deployment_port_test.yaml new file mode 100644 index 00000000..22f95a8c --- /dev/null +++ b/library/common-test/tests/pod/deployment_port_test.yaml @@ -0,0 +1,13 @@ +suite: deployment port test +templates: + - common.yaml +tests: + - it: should pass with default values + asserts: + - hasDocuments: + count: 1 + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + +TODO: ports diff --git a/library/common-test/tests/pod/deployment_volume_test.yaml b/library/common-test/tests/pod/deployment_volume_test.yaml new file mode 100644 index 00000000..5666e785 --- /dev/null +++ b/library/common-test/tests/pod/deployment_volume_test.yaml @@ -0,0 +1,151 @@ +suite: deployment volume test +templates: + - common.yaml +tests: + - it: should pass with default values + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - isNull: + path: spec.template.spec.volume + + - it: should pass with added emptyDir volume + set: + persistence: + volume1: + enabled: true + type: emptyDir + sizeLimit: 1Gi + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + emptyDir: + sizeLimit: 1Gi + + - it: should pass with added emptyDir volume and no sizeLimit + set: + persistence: + volume1: + enabled: true + type: emptyDir + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + emptyDir: {} + + - it: should pass with added emptyDir volume memory backed with sizeLimit + set: + persistence: + volume1: + enabled: true + type: emptyDir + medium: Memory + sizeLimit: 1Gi + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + emptyDir: + medium: Memory + sizeLimit: 1Gi + + - it: should pass with added emptyDir volume memory backed with sizeLimit via tpl + set: + some_medium: Memory + some_size: 1Gi + persistence: + volume1: + enabled: true + type: emptyDir + medium: "{{ .Values.some_medium }}" + sizeLimit: "{{ .Values.some_size }}" + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + emptyDir: + medium: Memory + sizeLimit: 1Gi + + - it: should pass with added emptyDir volume memory backed and no sizeLimit + set: + persistence: + volume1: + enabled: true + type: emptyDir + medium: Memory + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + emptyDir: + medium: Memory + + - it: should pass with added nfs + set: + persistence: + volume1: + enabled: true + type: nfs + server: some.server.local + path: /nfs/path + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + nfs: + server: some.server.local + path: /nfs/path + + - it: should pass with added hostPath + set: + persistence: + volume1: + enabled: true + type: hostpath + hostPath: /mnt/pool/test + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + hostPath: + path: /mnt/pool/test + + - it: should pass with added hostPath and hostPathType set via tpl + set: + some_key: Directory + persistence: + volume1: + enabled: true + type: hostpath + hostPathType: "{{ .Values.some_key }}" + hostPath: /mnt/pool/test + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: volume1 + hostPath: + path: /mnt/pool/test + type: Directory + - it: should fail with wrong persistence type + set: + persistence.some_volume.type: not_valid_persistence + persistence.some_volume.enabled: true + asserts: + - failedTemplate: + errorMessage: Not a valid persistence.type (not_valid_persistence) + +# TODO: configmap +# TODO: secret +# TODO: PVC diff --git a/library/common-test/tests/pods/deployment_test.yaml b/library/common-test/tests/pods/deployment_test.yaml deleted file mode 100644 index bec07fba..00000000 --- a/library/common-test/tests/pods/deployment_test.yaml +++ /dev/null @@ -1,336 +0,0 @@ -suite: pod deployment -templates: - - common.yaml -tests: - - it: should pass with default values - asserts: - - hasDocuments: - count: 1 - - containsDocument: - kind: Deployment - apiVersion: apps/v1 - - documentIndex: &deploymentDoc 0 - isKind: - of: Deployment - - equal: - documentIndex: *deploymentDoc - path: apiVersion - value: apps/v1 - - equal: - documentIndex: *deploymentDoc - path: metadata.name - value: RELEASE-NAME-common-test - - equal: - documentIndex: *deploymentDoc - path: metadata.labels - value: - app: common-test - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: common-test - app.kubernetes.io/version: v1.0.0 - helm-revision: "0" - helm.sh/chart: common-test-1.0.0 - release: RELEASE-NAME - - isNotEmpty: - documentIndex: *deploymentDoc - path: metadata.annotations.rollme - - equal: - documentIndex: *deploymentDoc - path: spec.revisionHistoryLimit - value: 3 - - equal: - documentIndex: *deploymentDoc - path: spec.replicas - value: 1 - - equal: - documentIndex: *deploymentDoc - path: spec.strategy.type - value: Recreate - - isNull: - documentIndex: *deploymentDoc - path: spec.strategy.rollingUpdate - - equal: - documentIndex: *deploymentDoc - path: spec.selector.matchLabels - value: - app: common-test - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: common-test - release: RELEASE-NAME - - - it: should pass with nameOverride - set: - nameOverride: overrodeName - asserts: - - equal: - documentIndex: *deploymentDoc - path: metadata.name - value: RELEASE-NAME-overrodeName - - - it: should pass with global.nameOverride - set: - nameOverride: overrodeName - global.nameOverride: globalOverrodeName - asserts: - - equal: - documentIndex: *deploymentDoc - path: metadata.name - value: RELEASE-NAME-globalOverrodeName - - - it: should pass with controller and global labels - set: - some_key: some_value - controller.labels: - controller_key: controller_value - controller_key2: "{{ .Values.some_key }}" - global.labels: - global_key: global_value - global_key2: "{{ .Values.some_key }}" - asserts: - - equal: - documentIndex: *deploymentDoc - path: metadata.labels - value: - controller_key: controller_value - controller_key2: some_value - global_key: global_value - global_key2: some_value - app: common-test - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: common-test - app.kubernetes.io/version: v1.0.0 - helm-revision: "0" - helm.sh/chart: common-test-1.0.0 - release: RELEASE-NAME - - - it: should pass with controller and global annotations - set: - some_key: some_value - controller.annotations: - controller_key: controller_value - controller_key2: "{{ .Values.some_key }}" - global.annotations: - global_key: global_value - global_key2: "{{ .Values.some_key }}" - asserts: - - equal: - documentIndex: *deploymentDoc - path: metadata.annotations.controller_key - value: controller_value - - equal: - documentIndex: *deploymentDoc - path: metadata.annotations.controller_key2 - value: some_value - - equal: - documentIndex: *deploymentDoc - path: metadata.annotations.global_key - value: global_value - - equal: - documentIndex: *deploymentDoc - path: metadata.annotations.global_key2 - value: some_value - - isNotEmpty: - documentIndex: *deploymentDoc - path: metadata.annotations.rollme - - - it: should pass with controller strategy changed and rollingUpdate strategies set - set: - controller.strategy: RollingUpdate - controller.rollingUpdate.unavailable: 2 - controller.rollingUpdate.surge: 3 - asserts: - - equal: - documentIndex: *deploymentDoc - path: spec.strategy.type - value: RollingUpdate - - equal: - documentIndex: *deploymentDoc - path: spec.strategy.rollingUpdate - value: - maxUnavailable: 2 - maxSurge: 3 - - - it: should pass with controller disabled - set: - controller.enabled: false - asserts: - - hasDocuments: - count: 0 - - - it: should pass with controller strategy changed - set: - controller.strategy: RollingUpdate - asserts: - - equal: - documentIndex: *deploymentDoc - path: spec.strategy.type - value: RollingUpdate - - isNull: - documentIndex: *deploymentDoc - path: spec.strategy.rollingUpdate - - - it: should pass with podAnnotations set - set: - some_key: some_value2 - podAnnotations.test: some_value - podAnnotations.test2: "{{ .Values.some_key }}" - asserts: - - equal: - documentIndex: *deploymentDoc - path: spec.template.metadata.annotations.test2 - value: some_value2 - - equal: - documentIndex: *deploymentDoc - path: spec.template.metadata.annotations.test - value: some_value - - - it: should pass with podLabels set - set: - some_key: some_value2 - podLabels.test: some_value - podLabels.test2: "{{ .Values.some_key }}" - asserts: - - equal: - documentIndex: *deploymentDoc - path: spec.template.metadata.labels.test2 - value: some_value2 - - equal: - documentIndex: *deploymentDoc - path: spec.template.metadata.labels.test - value: some_value - - - it: should pass with added emptyDir volume - set: - persistence: - volume1: - enabled: true - type: emptyDir - sizeLimit: 1Gi - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - emptyDir: - sizeLimit: 1Gi - - - it: should pass with added emptyDir volume and no sizeLimit - set: - persistence: - volume1: - enabled: true - type: emptyDir - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - emptyDir: {} - - - it: should pass with added emptyDir volume memory backed with sizeLimit - set: - persistence: - volume1: - enabled: true - type: emptyDir - medium: Memory - sizeLimit: 1Gi - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - emptyDir: - medium: Memory - sizeLimit: 1Gi - - - it: should pass with added emptyDir volume memory backed with sizeLimit via tpl - set: - some_medium: Memory - some_size: 1Gi - persistence: - volume1: - enabled: true - type: emptyDir - medium: "{{ .Values.some_medium }}" - sizeLimit: "{{ .Values.some_size }}" - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - emptyDir: - medium: Memory - sizeLimit: 1Gi - - - it: should pass with added emptyDir volume memory backed and no sizeLimit - set: - persistence: - volume1: - enabled: true - type: emptyDir - medium: Memory - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - emptyDir: - medium: Memory - - - it: should pass with added nfs - set: - persistence: - volume1: - enabled: true - type: nfs - server: some.server.local - path: /nfs/path - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - nfs: - server: some.server.local - path: /nfs/path - - - it: should pass with added hostPath - set: - persistence: - volume1: - enabled: true - type: hostpath - hostPath: /mnt/pool/test - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - hostPath: - path: /mnt/pool/test - - - it: should pass with added hostPath and hostPathType set via tpl - set: - some_key: Directory - persistence: - volume1: - enabled: true - type: hostpath - hostPathType: "{{ .Values.some_key }}" - hostPath: /mnt/pool/test - asserts: - - equal: - path: spec.template.spec.volumes[0] - value: - name: volume1 - hostPath: - path: /mnt/pool/test - type: Directory - -TODO: configmap -TODO: secret -TODO: PVC -TODO: ports