From c2183e63c89da541223226f3ed4ba7ce1c7cd1f4 Mon Sep 17 00:00:00 2001 From: David Kegley Date: Wed, 30 Oct 2024 12:57:08 -0400 Subject: [PATCH] Add helm unittesting scaffolds --- .github/workflows/chart-test.yaml | 22 +++++++++++++ .gitignore | 5 +++ CONTRIBUTING.md | 13 ++++++++ .../tests/service-accounts_test.yaml | 32 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 charts/rstudio-connect/tests/service-accounts_test.yaml diff --git a/.github/workflows/chart-test.yaml b/.github/workflows/chart-test.yaml index f0e1712c..a46ab3e7 100644 --- a/.github/workflows/chart-test.yaml +++ b/.github/workflows/chart-test.yaml @@ -79,6 +79,28 @@ jobs: if: steps.ct-lint.outcome == 'failure' || steps.ct-lint-all.outcome == 'failure' run: exit 1 + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + with: + version: v3.6.3 + + - name: Install helm unittest plugin + run: helm plugin install --version v0.6.3 https://github.com/helm-unittest/helm-unittest.git + + - name: Run chart unit tests + run: | + for dir in $(ls -d charts/*/); do + helm unittest $dir + done + install: runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index fdc6c0f6..ba4ec178 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,10 @@ helm-docs charts/**/charts/ /*.values /.cr-release-packages + +# helm unittest plugin +__snapshot__ + bin/** !bin/README.md @@ -10,3 +14,4 @@ _site/ _publish.yml /.quarto/ + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e2cdce7..7aeba09d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,19 @@ We'll try to be as responsive as possible in reviewing and accepting pull reques - If `index.yaml` gets out of date on the repository, see [`./scripts/`](./scripts) for a workflow to fix +## Testing + +Running the [helm chart unit tests](https://github.com/helm-unittest/helm-unittest): + +``` +# install the unittest plugin +helm plugin install https://github.com/helm-unittest/helm-unittest.git + +# run the rstudio-connect chart unittests +# unit tests are defined in `charts/$CHART_NAME/tests` +helm unittest --color ./charts/rstudio-connect +``` + ## Templates The `rstudio-workbench` and `rstudio-connect` charts both make heavy use of the "templating" feature of the Posit Job diff --git a/charts/rstudio-connect/tests/service-accounts_test.yaml b/charts/rstudio-connect/tests/service-accounts_test.yaml new file mode 100644 index 00000000..9e68cc65 --- /dev/null +++ b/charts/rstudio-connect/tests/service-accounts_test.yaml @@ -0,0 +1,32 @@ +suite: Connect Service Accounts +templates: + - configmap.yaml + - configmap-prestart.yaml + - deployment.yaml +tests: + - it: should set the Connect pod service account when the launcher is enabled + template: deployment.yaml + set: + launcher: + enabled: true + rbac: + create: true + serviceAccount: + name: "connect-service-account" + asserts: + - equal: + path: "spec.template.spec.serviceAccountName" + value: "connect-service-account" + - it: should set the Connect pod service account when the launcher is not enabled + template: deployment.yaml + set: + launcher: + enabled: false + rbac: + create: true + serviceAccount: + name: "connect-service-account" + asserts: + - equal: + path: "spec.template.spec.serviceAccountName" + value: "connect-service-account"