Skip to content

Update unittests to support new version of helm unittest #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions charts/gitops-runtime/tests/app-proxy-image-enrichemnt_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests:
app-proxy.image-enrichment.enabled: true
asserts:
- failedTemplate:
errorMessage: 'app-proxy.image-enrichment is enabled but argo-workflows is disabled. This is not suppurted. Either disable erichment or enable workflows'
errorMessage: 'ERROR: app-proxy.image-enrichment is enabled but argo-workflows is disabled. This is not suppurted. Either disable erichment or enable workflows'

- it: Set correct values in app-proxy configmap
template: 'app-proxy/config.yaml'
Expand All @@ -31,7 +31,7 @@ tests:
app-proxy.image-enrichment.config.clientHeartbeatIntervalInSeconds: 1
app-proxy.image-enrichment.serviceAccount.name: test
app-proxy.image-enrichment.config.images:
reportImage:
reportImage:
registry: registry.example
repository: codefresh/report-image
tag: 1-test-report
Expand Down Expand Up @@ -61,19 +61,19 @@ tests:
- equal:
path: data.enrichmentTtlActiveInSeconds
value: "1"
- equal:
- equal:
path: data.enrichmentClientHeartbeatIntervalInSeconds
value: "1"
- equal:
- equal:
path: data.enrichmentServiceAccountName
value: test
- equal:
- equal:
path: data.enrichmentImageReportingImage
value: registry.example/codefresh/report-image:1-test-report
- equal:
- equal:
path: data.enrichmentGitEnrichmentImage
value: reg.ex/codefresh/git-enrich:1-test-git
- equal:
- equal:
path: data.enrichmentJiraEnrichmentImage
value: my.reg/codefresh/jira-enrich:1-test-jira

Expand Down Expand Up @@ -147,7 +147,7 @@ tests:
name: cap-app-proxy-cm
key: enrichmentServiceAccountName
optional: true
- contains:
- contains:
path: spec.template.spec.containers[0].env
content:
name: IRW_REPORT_IMAGE_TASK_IMAGE
Expand All @@ -156,7 +156,7 @@ tests:
name: cap-app-proxy-cm
key: enrichmentImageReportingImage
optional: true
- contains:
- contains:
path: spec.template.spec.containers[0].env
content:
name: IRW_GIT_ENRICHMENT_TASK_IMAGE
Expand All @@ -165,7 +165,7 @@ tests:
name: cap-app-proxy-cm
key: enrichmentGitEnrichmentImage
optional: true
- contains:
- contains:
path: spec.template.spec.containers[0].env
content:
name: IRW_JIRA_ENRICHMENT_TASK_IMAGE
Expand Down Expand Up @@ -202,8 +202,3 @@ tests:
- equal:
path: roleRef.name
value: cap-app-proxy-enrichment





Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Test components that depend on templates from Argo projects.
# Test components that depend on templates from Argo projects.
# This is extremely important since currently templates are used that may change between versions of Argo charts.
suite: Test integration of outputs from Argo Project templates with components that use them in the runtime chart
templates:
Expand All @@ -8,9 +8,9 @@ templates:
- internal-router/config.yaml
- event-reporters/events-reporter/eventsource.yaml
- event-reporters/rollout-reporter/clusterrolebinding.yaml
tests:
tests:
# ------------------------------------------------------------------------
# ArgoCD
# ArgoCD
# Affected templates: app-proxy configmap and events-reporter eventsource
# ------------------------------------------------------------------------
- it: test app proxy argocd url - http
Expand Down Expand Up @@ -61,7 +61,7 @@ tests:
path: spec.generic.events.url
value: argo-cd-test-server:443
# ------------------------------------------------------------------------------------------
# Argo Workflows
# Argo Workflows
# Affected templates: app-proxy ClusterRoleBinding to argo-server role, intenal-url config
# ------------------------------------------------------------------------------------------
- it: test app proxy ClusterRoleBinding to argo workflows role
Expand All @@ -87,7 +87,7 @@ tests:
argo-workflows.server.secure: true
asserts:
- matchRegex:
path: data.default\.conf\.template
path: data["default.conf.template"]
pattern: .proxy_pass https://argo-test-server:2746+

- it: check worklfow route users argo-workflows server name and protocol http
Expand All @@ -101,7 +101,7 @@ tests:
argo-workflows.server.secure: false
asserts:
- matchRegex:
path: data.default\.conf\.template
path: data["default.conf.template"]
pattern: .proxy_pass http://argo-test-server:2746+

- it: test app proxy argocd workflows url - http
Expand Down Expand Up @@ -130,7 +130,7 @@ tests:
path: data.argoWorkflowsUrl
value: https://argo-test-server:2746
# ------------------------------------------------------------------------------------------
# Argo rollouts
# Argo rollouts
# Affected templates - rollouts reporter clusterrolebinding
# ------------------------------------------------------------------------------------------
- it: test rollout reporter ClusterRoleBinding to argo rollouts role
Expand All @@ -143,4 +143,4 @@ tests:
asserts:
- equal:
path: roleRef.name
value: rollouts-test
value: rollouts-test
7 changes: 3 additions & 4 deletions charts/gitops-runtime/tests/custom-ca_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -379,25 +379,24 @@ tests:
values:
- ./values/mandatory-values.yaml
asserts:
- isEmpty:
- notExists:
path: spec.triggers[0].template.http.tls

- it: rollout reporter sensor - no tls
template: event-reporters/rollout-reporter/sensor.yaml
values:
- ./values/mandatory-values.yaml
asserts:
- isEmpty:
- notExists:
path: spec.triggers[0].template.http.tls

- it: workflow reporter sensor - no tls
template: event-reporters/workflow-reporter/sensor.yaml
values:
- ./values/mandatory-values.yaml
asserts:
- isEmpty:
- notExists:
path: spec.triggers[0].template.http.tls

# --------------------------------------------------------
# workflowPipelinesGitWebhooks
# --------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions charts/gitops-runtime/tests/gitops-controller-misc_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ templates:
tests:
- it: override both images works
template: 'charts/gitops-operator/templates/deployment.yaml'
values:
- ./values/mandatory-values.yaml
set:
gitops-operator:
image:
Expand Down Expand Up @@ -195,43 +197,54 @@ tests:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
name: codefresh-gitops-operator-proxy
any: true
- containsDocument:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: codefresh-gitops-operator-proxy
any: true
- containsDocument:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: restrictedgitsource-editor
any: true
- containsDocument:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
name: restrictedgitsource-editor
any: true
- containsDocument:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
name: restrictedgitsource-viewer
any: true
- containsDocument:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
name: codefresh-gitops-operator
any: true
- containsDocument:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: codefresh-gitops-operator
any: true
- containsDocument:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: restrictedgitsource-viewer
any: true
- containsDocument:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
name: leader-election
any: true
- containsDocument:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
name: leader-election
any: true
- containsDocument:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: leader-election
any: true
6 changes: 3 additions & 3 deletions charts/gitops-runtime/tests/ingress_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tests:
tunnel-client.enabled: false
asserts:
- failedTemplate:
errorMessage: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided
errorMessage: "ERROR: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided"

- it: fail on ingressUrl that is not http or https
template: templates/codefresh-cm.yaml
Expand All @@ -65,7 +65,7 @@ tests:
global.runtime.ingressUrl: test.test.fail
asserts:
- failedTemplate:
errorMessage: Only http and https are supported for global.runtime.ingressUrl
errorMessage: "ERROR: Only http and https are supported for global.runtime.ingressUrl"

- it: codefresh-cm ingressHost is set correctly when ingress enabled
template: templates/codefresh-cm.yaml
Expand Down Expand Up @@ -130,4 +130,4 @@ tests:
value:
- hosts:
- "test.example.com"
secretName: blah
secretName: blah
14 changes: 6 additions & 8 deletions charts/gitops-runtime/tests/runtime-gitcredentials_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ tests:
- ./values/mandatory-values.yaml
set:
global.runtime.gitCredentials.password.value: bar
assert:
- contains:
path: metadata
content:
name: test-runtime1-git-password
asserts:
- hasDocuments:
count: 1

- it: secret not created for secretKeyRef
template: 'git-password-secret.yaml'
Expand All @@ -23,7 +21,7 @@ tests:
set:
global.runtime.gitCredentials.password.secretKeyRef.name: bar
global.runtime.gitCredentials.password.secretKeyRef.key: foo
assert:
asserts:
- hasDocuments:
count: 0

Expand Down Expand Up @@ -71,7 +69,7 @@ tests:
secretKeyRef:
name: bar
key: foo
optional: true
optional: true

- it: Plain text value takes precedence
template: 'app-proxy/deployment.yaml'
Expand Down Expand Up @@ -115,4 +113,4 @@ tests:
global.runtime.gitCredentials.password.secretKeyRef.name: foo
asserts:
- failedTemplate:
errorMessage: 'secretKeyRef for global.runtime.gitCredentials.password illegal - must have key field'
errorMessage: 'secretKeyRef for global.runtime.gitCredentials.password illegal - must have key field'
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tests:
argo-workflows.enabled: false
asserts:
- notMatchRegex:
path: data.default\.conf\.template
path: data["default.conf.template"]
pattern: .+/workflows.+

- it: internal router config has workflows route when workflows enabled
Expand All @@ -57,7 +57,7 @@ tests:
argo-workflows.enabled: true
asserts:
- matchRegex:
path: data.default\.conf\.template
path: data["default.conf.template"]
pattern: .+/workflows.+

- it: test app proxy empty argo workflows url when disabled
Expand All @@ -69,4 +69,4 @@ tests:
asserts:
- equal:
path: data.argoWorkflowsUrl
value:
value:
8 changes: 8 additions & 0 deletions scripts/helm-unittests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
## Reference: https://github.com/norwoodj/helm-docs
set -eux
CHART_DIR="$(cd "$(dirname "$0")/.." && pwd)"
echo "$CHART_DIR"

echo "Running Helm unittests"
docker run --entrypoint "/bin/sh" -it --rm -v $CHART_DIR/charts:/charts alpine/helm:3.14.4 -c 'helm plugin install https://github.com/helm-unittest/helm-unittest.git --version 0.5.1 && helm unittest /charts/gitops-runtime'