From 8d332f7e5eeadb9316d1e5842a99525baa9ee0b5 Mon Sep 17 00:00:00 2001 From: david tsai <100375199+dtsai-czi@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:19:54 -0700 Subject: [PATCH] feat: (CCIE-3082) add unit testing to GHA (#64) --- .github/workflows/unittest.yaml | 13 ++++++++++ stack/.helmignore | 2 ++ stack/tests/deployment_test.yaml | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 .github/workflows/unittest.yaml create mode 100644 stack/tests/deployment_test.yaml diff --git a/.github/workflows/unittest.yaml b/.github/workflows/unittest.yaml new file mode 100644 index 0000000..fb6ade6 --- /dev/null +++ b/.github/workflows/unittest.yaml @@ -0,0 +1,13 @@ +name: Unit testing + +on: pull_request + +jobs: + unittest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: d3adb5/helm-unittest-action@v2 + with: + helm-version: v3.8.0 + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/stack/.helmignore b/stack/.helmignore index 0e8a0eb..c3b4508 100644 --- a/stack/.helmignore +++ b/stack/.helmignore @@ -21,3 +21,5 @@ .idea/ *.tmproj .vscode/ +# testing +tests \ No newline at end of file diff --git a/stack/tests/deployment_test.yaml b/stack/tests/deployment_test.yaml new file mode 100644 index 0000000..f635c95 --- /dev/null +++ b/stack/tests/deployment_test.yaml @@ -0,0 +1,42 @@ +suite: test deployment +templates: + - deployment.yaml +tests: + - it: should work + set: + services: + service1: + args: ["arg1", "arg2"] + command: ["command1", "command2"] + autoscaling: + enabled: true + minReplicas: 2 + maxReplicas: 10 + maxUnavailable: 1 + replicaCount: 2 + sidecars: + - name: sidecar1 + image: "sidecar1:latest" + - name: sidecar2 + image: "sidecar2:latest" + initContainers: + - name: initContainer1 + image: "alpine:latest" + command: ["echo", "Hello World"] + asserts: + - isKind: + of: Deployment + - isSubset: + path: spec + content: + revisionHistoryLimit: 3 + any: true + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + + # path: metadata.name + # pattern: -my-chart$ + # - equal: + # path: spec.template.spec.containers[0].image + # value: nginx:latest \ No newline at end of file