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

Update unit tests to be current with most recent helm unittest syntax #619

Merged
merged 2 commits into from
Jan 17, 2025
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
6 changes: 3 additions & 3 deletions TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ helm lint charts/sourcegraph/.

## Unit testing

We utilize [helm-unittest](https://github.com/quintush/helm-unittest/), a BDD styled unit test framework, to validate our helm chart.
We utilize [helm-unittest](https://github.com/helm-unittest/helm-unittest/), a BDD styled unit test framework, to validate our helm chart.

helm-unittest can be installed with:

```bash
helm plugin install https://github.com/quintush/helm-unittest
helm plugin install https://github.com/helm-unittest/helm-unittest
```

Once the plugin is installed, you can run the unit tests using the following:
Expand All @@ -28,7 +28,7 @@ helm unittest --helm3 ./charts/sourcegraph/.

We currently do not have testing best practices or require unit tests for new changes, so add test cases at your best judgement if possible.

You may check out our [existing test cases](https://github.com/sourcegraph/deploy-sourcegraph-helm/tree/main/charts/sourcegraph/tests) and helm-unittest [docs](https://github.com/quintush/helm-unittest/blob/master/DOCUMENT.md).
You may check out our [existing test cases](https://github.com/sourcegraph/deploy-sourcegraph-helm/tree/main/charts/sourcegraph/tests) and helm-unittest [docs](https://github.com/helm-unittest/helm-unittest/blob/master/DOCUMENT.md).

## Manual testing

Expand Down
10 changes: 5 additions & 5 deletions charts/sourcegraph/tests/checksum_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ tests:
existingSecret: "my-secret"
asserts:
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/auth]
path: spec.template.metadata.annotations["checksum/auth"]
- it: should update checksum when codeintel-db secret is modified
set:
codeIntelDB:
auth:
newkey: "blank"
asserts:
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/auth]
path: spec.template.metadata.annotations["checksum/auth"]
- it: should update checksum when codeinsights-db secret is modified
set:
codeInsightsDB:
Expand All @@ -27,20 +27,20 @@ tests:
database: "anotherdb"
asserts:
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/auth]
path: spec.template.metadata.annotations["checksum/auth"]
- it: should update checksum when redis-store secret is modified
set:
redisStore:
connection:
endpoint: "external-redis:6379"
asserts:
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/auth]
path: spec.template.metadata.annotations["checksum/auth"]
- it: should update checksum when redis-cache secret is modified
set:
redisCache:
connection:
endpoint: "external-redis:6379"
asserts:
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/auth]
path: spec.template.metadata.annotations["checksum/auth"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests:
max_connections = 3000000000000000000
asserts:
- matchRegex:
path: data.postgresql\.conf
path: data["postgresql.conf"]
pattern: max_connections = 3000000000000000000
- it: should fail to render when both codeInsightsDB.additionalConfig and codeInsightsDB.existingConfig are defined
set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests:
max_connections = 3000000000000000000
asserts:
- matchRegex:
path: data.postgresql\.conf
path: data["postgresql.conf"]
pattern: max_connections = 2000000000000000000
- it: should fail to render when both codeIntelDB.additionalConfig and codeIntelDB.existingConfig are defined
set:
Expand Down
16 changes: 8 additions & 8 deletions charts/sourcegraph/tests/defaultTagPrefix_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ tests:
frontend:
image:
defaultTag: test
matchRegexRaw:
path: "spec.template.spec.containers[0].image"
pattern: |
"[\w-]+\.\w+\.\w+\/.+\/.+:test"
asserts:
- matchRegex:
path: "spec.template.spec.containers[0].image"
pattern: ^[\w-]+\.\w+\.\w+\/.+\/.+:test$
- it: should add defaultTagPrefix
template: frontend/sourcegraph-frontend.Deployment.yaml
set:
frontend:
image:
defaultTag: test
defaultTagPrefix: "prefix-"
matchRegexRaw:
path: "spec.template.spec.containers[0].image"
pattern: |
"[\w-]+\.\w+\.\w+\/.+\/.+:prefix-test"
asserts:
- matchRegex:
path: "spec.template.spec.containers[0].image"
pattern: ^[\w-]+\.\w+\.\w+\/.+\/.+:prefix-test$
8 changes: 4 additions & 4 deletions charts/sourcegraph/tests/localDevMode_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ tests:
set:
sourcegraph.localDevMode: true
asserts:
- isEmpty:
path: spec.template.spec.containers[0].resources
- notExists:
path: "spec.template.spec.containers[0].resources"

- it: should have a resource block when localDevMode=false
set:
sourcegraph.localDevMode: false
asserts:
- isNotEmpty:
path: spec.template.spec.containers[0].resources
- exists:
path: "spec.template.spec.containers[0].resources"
2 changes: 1 addition & 1 deletion charts/sourcegraph/tests/nodeExporter_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ tests:
create: false
name: "test-service-account-name"
asserts:
- isEmpty:
- notExists:
path: spec.template.spec.serviceAccountName
template: node-exporter/node-exporter.DaemonSet.yaml

Expand Down
2 changes: 1 addition & 1 deletion charts/sourcegraph/tests/otelCollectorJaeger_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tests:
count: 1 # ConfigMap is rendered
template: otel-collector/otel-collector.ConfigMap.yaml
- matchRegex:
path: data.[config.yaml]
path: data["config.yaml"]
pattern: "endpoint: otlp.service.com:443" # check if element of config is substituted correctly
template: otel-collector/otel-collector.ConfigMap.yaml
- it: should fail if a configuration is provided and jaeger is enabled
Expand Down
2 changes: 1 addition & 1 deletion charts/sourcegraph/tests/pgsqlAdditionalConfig_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tests:
max_connections = 3000000000000000000
asserts:
- matchRegex:
path: data.postgresql\.conf
path: data["postgresql.conf"]
pattern: max_connections = 1000000000000000000
- it: should fail to render when both pgsql.additionalConfig and pgsql.existingConfig are defined
set:
Expand Down
4 changes: 2 additions & 2 deletions charts/sourcegraph/tests/pgsqlAuth_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests:
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
value: "my-secret"
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/pgsql.secret]
path: spec.template.metadata.annotations["checksum/pgsql.secret"]
- it: should not generate a secret when existingSecret is passed
template: pgsql/pgsql.Secret.yaml
set:
Expand Down Expand Up @@ -62,4 +62,4 @@ tests:
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
value: "pgsql-auth"
- matchSnapshot:
path: spec.template.metadata.annotations.[checksum/pgsql.secret]
path: spec.template.metadata.annotations["checksum/pgsql.secret"]
4 changes: 2 additions & 2 deletions charts/sourcegraph/tests/storageClass_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ tests:
create: true
type: null
asserts:
- isNull:
path: parameters
- notExists:
path: parameters.type
- it: should have 'allowedTopologies` when storageClass.allowedTopologies is set
set:
storageClass:
Expand Down
2 changes: 1 addition & 1 deletion charts/sourcegraph/tests/worker_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tests:
content:
name: WORKER_JOB_BLOCKLIST
value: job1,job2,job3,job4,rogue-job-1,rogue-job-2
- isEmpty:
- notExists:
path: spec.selector.matchLabels.worker-replica
- it: should have the correct worker-0 deployment
template: worker/worker.Deployment.yaml
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/helm-unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euf -o pipefail

### Install the helm-unittest plugin
helm plugin install https://github.com/quintush/helm-unittest --version v0.2.11
helm plugin install https://github.com/helm-unittest/helm-unittest

### Run the helm tests
helm unittest -3q charts/sourcegraph
helm unittest -q charts/sourcegraph
Loading