Skip to content
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

Feat helm unittest #334

Merged
merged 18 commits into from
Feb 21, 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
5 changes: 4 additions & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: install helm unittests
if: steps.list-changed.outputs.changed == 'true'
run: |
helm plugin install --version v0.3.6 https://github.com/helm-unittest/helm-unittest
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# IDE or Editor-specific
.idea/
.vscode/
2 changes: 1 addition & 1 deletion charts/atlantis/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
appVersion: v0.27.0
description: A Helm chart for Atlantis https://www.runatlantis.io
name: atlantis
version: 4.19.0
version: 4.20.0
keywords:
- terraform
home: https://www.runatlantis.io
Expand Down
2 changes: 1 addition & 1 deletion charts/atlantis/templates/secret-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data:
{{- if .Values.bitbucket.baseURL }}
bitbucket_secret: {{ required "bitbucket.secret is required if bitbucket.baseURL is specified." .Values.bitbucket.secret | b64enc }}
{{- end}}
{{- end }}
{{- end }}
{{- if .Values.azuredevops }}
azuredevops_token: {{ required "azuredevops.token is required if azuredevops configuration is specified." .Values.azuredevops.token | b64enc }}
azuredevops_webhook_password: {{ required "azuredevops.webhookPassword is required if azuredevops configuration is specified." .Values.azuredevops.webhookPassword | b64enc }}
Expand Down
6 changes: 3 additions & 3 deletions charts/atlantis/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ spec:
{{- if .Values.command }}
command:
{{- range .Values.command }}
- {{ . }}
{{- end }}
{{- end }}
- {{ . }}
{{- end }}
{{- end }}
args:
- server
{{- if .Values.config }}
Expand Down
38 changes: 38 additions & 0 deletions charts/atlantis/tests/secret-api_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
suite: test secret-api for api secret
templates:
- secret-api.yaml
release:
name: my-release
tests:
- it: default values
asserts:
- hasDocuments:
count: 0
- it: apiSecretName
set:
apiSecretName: 'atlantis-api'
asserts:
- hasDocuments:
count: 0
- it: apiSecret
set:
api.secret: 'spongebob'
commonLabels:
team: "infra"
asserts:
- hasDocuments:
count: 1
- isKind:
of: Secret
- isAPIVersion:
of: v1
- equal:
path: metadata.name
value: my-release-atlantis-api
- equal:
path: data["apisecret"]
value: c3BvbmdlYm9i
- equal:
path: metadata.labels.team
value: infra
52 changes: 52 additions & 0 deletions charts/atlantis/tests/secret-aws_test.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work. You beat me to it!

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
suite: test secret-aws for aws
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind also adding a github action for this?

# .github/workflows/tests.yaml
name: tests

on: pull_request

jobs:
  unittest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: d3adb5/helm-unittest-action@v2
        with:
          # https://github.com/helm/helm/releases
          helm-version: v3.13.2
          github-token: ${{ secrets.GITHUB_TOKEN }}

Copy link
Member

@GMartinez-Sisti GMartinez-Sisti Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this job is added, then it needs to be removed from ct lint

helm-charts/ct.yaml

Lines 7 to 8 in f400585

additional-commands:
- helm unittest {{ .Path }}

templates:
- secret-aws.yaml
release:
name: my-release
tests:
- it: default values
asserts:
- hasDocuments:
count: 0
- it: awsSecretName
set:
awsSecretName: 'atlantis-aws'
asserts:
- hasDocuments:
count: 0
- it: aws
set:
aws:
credentials: |
[default]
aws_access_key_id=YOUR_ACCESS_KEY_ID
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=us-east-1
config: |
[profile a_role_to_assume]
role_arn = arn:aws:iam::123456789:role/service-role/roleToAssume
source_profile = default
commonLabels:
team: "infra"
asserts:
- hasDocuments:
count: 1
- isKind:
of: Secret
- isAPIVersion:
of: v1
- equal:
path: metadata.name
value: my-release-atlantis-aws
- equal:
path: data["config"]
value: W3Byb2ZpbGUgYV9yb2xlX3RvX2Fzc3VtZV0Kcm9sZV9hcm4gPSBhcm46YXdzOmlhbTo6MTIzNDU2Nzg5OnJvbGUvc2VydmljZS1yb2xlL3JvbGVUb0Fzc3VtZQpzb3VyY2VfcHJvZmlsZSA9IGRlZmF1bHQK
- equal:
path: data["credentials"]
value: W2RlZmF1bHRdCmF3c19hY2Nlc3Nfa2V5X2lkPVlPVVJfQUNDRVNTX0tFWV9JRAphd3Nfc2VjcmV0X2FjY2Vzc19rZXk9WU9VUl9TRUNSRVRfQUNDRVNTX0tFWQpyZWdpb249dXMtZWFzdC0xCg==
- equal:
path: metadata.labels.team
value: infra


44 changes: 44 additions & 0 deletions charts/atlantis/tests/secret-basic-auth_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
suite: test secret-basic-auth for git basic-auth secret
templates:
- secret-basic-auth.yaml
release:
name: my-release
tests:
- it: default values
asserts:
- hasDocuments:
count: 0
- it: basicAuthSecretName
set:
basicAuthSecretName: "atlantis-basic-auth"
asserts:
- hasDocuments:
count: 0
- it: basicAuth
set:
basicAuth:
username: "atlantis"
password: "forever"
commonLabels:
team: "infra"
asserts:
- hasDocuments:
count: 1
- isKind:
of: Secret
- isAPIVersion:
of: v1
- equal:
path: metadata.name
value: my-release-atlantis-basic-auth
- equal:
path: data["username"]
value: YXRsYW50aXM=
- equal:
path: data["password"]
value: Zm9yZXZlcg==
- equal:
path: metadata.labels.team
value: infra

45 changes: 45 additions & 0 deletions charts/atlantis/tests/secret-gitconfig_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
suite: test secret-gitconfig for gitconfig
templates:
- secret-gitconfig.yaml
release:
name: my-release
tests:
- it: default values
template: secret-gitconfig.yaml
asserts:
- hasDocuments:
count: 0
- it: gitconfigSecretName
template: secret-gitconfig.yaml
set:
gitconfigSecretName: 'atlantis-gitconfig'
asserts:
- hasDocuments:
count: 0
- it: gitconfig
template: secret-gitconfig.yaml
set:
gitconfig: |
[url "https://[email protected]"]
insteadOf = https://github.com
commonLabels:
team: "infra"
asserts:
- hasDocuments:
count: 1
- isKind:
of: Secret
- isAPIVersion:
of: v1
- equal:
path: metadata.name
value: my-release-atlantis-gitconfig
- equal:
path: data["gitconfig"]
value: W3VybCAiaHR0cHM6Ly9ZT1VSX0dIX1RPS0VOQGdpdGh1Yi5jb20iXQppbnN0ZWFkT2YgPSBodHRwczovL2dpdGh1Yi5jb20K
- equal:
path: metadata.labels.team
value: infra


42 changes: 42 additions & 0 deletions charts/atlantis/tests/secret-netrc_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
suite: test secret-netrc for netrc
templates:
- secret-netrc.yaml
release:
name: my-release
tests:
- it: default values
asserts:
- hasDocuments:
count: 0
- it: netrcSecretName
set:
netrcSecretName: 'atlantis-netrc'
asserts:
- hasDocuments:
count: 0
- it: netrc
set:
netrc: |
machine artifactory.myapp.com login YOUR_USERNAME password YOUR_PASSWORD
machine bitbucket.myapp.com login YOUR_USERNAME password YOUR_PASSWORD
commonLabels:
team: "infra"
asserts:
- hasDocuments:
count: 1
- isKind:
of: Secret
- isAPIVersion:
of: v1
- equal:
path: metadata.name
value: my-release-atlantis-netrc
- equal:
path: data["netrc"]
value: bWFjaGluZSBhcnRpZmFjdG9yeS5teWFwcC5jb20gbG9naW4gWU9VUl9VU0VSTkFNRSBwYXNzd29yZCBZT1VSX1BBU1NXT1JECm1hY2hpbmUgYml0YnVja2V0Lm15YXBwLmNvbSBsb2dpbiBZT1VSX1VTRVJOQU1FIHBhc3N3b3JkIFlPVVJfUEFTU1dPUkQK
- equal:
path: metadata.labels.team
value: infra


57 changes: 57 additions & 0 deletions charts/atlantis/tests/secret-service-account_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
suite: test secret-service-account for serviceAccountSecrets
templates:
- secret-service-account.yaml
release:
name: my-release
tests:
- it: default values
template: secret-service-account.yaml
asserts:
- hasDocuments:
count: 0
- it: serviceAccountSecrets
template: secret-service-account.yaml
set:
serviceAccountSecrets:
credentials: VG9ueSBTb3ByYW5v
credentials-staging: Q2FybWVsYSBTb3ByYW5v
commonLabels:
team: infra
asserts:
- hasDocuments:
count: 2
- isKind:
of: Secret
- isAPIVersion:
of: v1
- equal:
path: metadata.labels.component
value: service-account-secret
- documentIndex: 0
equal:
path: data["service-account.json"]
value: VG9ueSBTb3ByYW5v
- documentIndex: 0
equal:
path: metadata.name
value: credentials
- documentIndex: 0
equal:
path: metadata.labels.team
value: infra
- documentIndex: 1
equal:
path: data["service-account.json"]
value: Q2FybWVsYSBTb3ByYW5v
- documentIndex: 1
equal:
path: metadata.name
value: credentials-staging
- documentIndex: 1
equal:
path: metadata.labels.team
value: infra



Loading
Loading