Skip to content

Commit d1b1a39

Browse files
authored
Update unit tests to be current with most recent helm unittest syntax (#619)
- Switch to the canonical helm unittest isntead of an outdated fork. - Update the tests to work with latest syntax. ### Checklist - [ ] Follow the [manual testing process](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/TEST.md) - [ ] Update [changelog](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/charts/sourcegraph/CHANGELOG.md) - [ ] Update [Kubernetes update doc](https://docs.sourcegraph.com/admin/updates/kubernetes) ### Test plan 1. uninstall the outdated helm unittest fork: `helm plugin uninstall unittest` 2. install the canonical tool: `helm plugin install https://github.com/helm-unittest/helm-unittest` 3. run the unit tests: `helm unittest ./charts/sourcegraph/.`
1 parent bbc07a1 commit d1b1a39

13 files changed

+32
-32
lines changed

TEST.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ helm lint charts/sourcegraph/.
1212

1313
## Unit testing
1414

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

1717
helm-unittest can be installed with:
1818

1919
```bash
20-
helm plugin install https://github.com/quintush/helm-unittest
20+
helm plugin install https://github.com/helm-unittest/helm-unittest
2121
```
2222

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

2929
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.
3030

31-
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).
31+
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).
3232

3333
## Manual testing
3434

charts/sourcegraph/tests/checksum_test.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ tests:
1010
existingSecret: "my-secret"
1111
asserts:
1212
- matchSnapshot:
13-
path: spec.template.metadata.annotations.[checksum/auth]
13+
path: spec.template.metadata.annotations["checksum/auth"]
1414
- it: should update checksum when codeintel-db secret is modified
1515
set:
1616
codeIntelDB:
1717
auth:
1818
newkey: "blank"
1919
asserts:
2020
- matchSnapshot:
21-
path: spec.template.metadata.annotations.[checksum/auth]
21+
path: spec.template.metadata.annotations["checksum/auth"]
2222
- it: should update checksum when codeinsights-db secret is modified
2323
set:
2424
codeInsightsDB:
@@ -27,20 +27,20 @@ tests:
2727
database: "anotherdb"
2828
asserts:
2929
- matchSnapshot:
30-
path: spec.template.metadata.annotations.[checksum/auth]
30+
path: spec.template.metadata.annotations["checksum/auth"]
3131
- it: should update checksum when redis-store secret is modified
3232
set:
3333
redisStore:
3434
connection:
3535
endpoint: "external-redis:6379"
3636
asserts:
3737
- matchSnapshot:
38-
path: spec.template.metadata.annotations.[checksum/auth]
38+
path: spec.template.metadata.annotations["checksum/auth"]
3939
- it: should update checksum when redis-cache secret is modified
4040
set:
4141
redisCache:
4242
connection:
4343
endpoint: "external-redis:6379"
4444
asserts:
4545
- matchSnapshot:
46-
path: spec.template.metadata.annotations.[checksum/auth]
46+
path: spec.template.metadata.annotations["checksum/auth"]

charts/sourcegraph/tests/codeInsightsDBAdditionalConfig_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tests:
1515
max_connections = 3000000000000000000
1616
asserts:
1717
- matchRegex:
18-
path: data.postgresql\.conf
18+
path: data["postgresql.conf"]
1919
pattern: max_connections = 3000000000000000000
2020
- it: should fail to render when both codeInsightsDB.additionalConfig and codeInsightsDB.existingConfig are defined
2121
set:

charts/sourcegraph/tests/codeIntelDBAdditionalConfig_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tests:
1515
max_connections = 3000000000000000000
1616
asserts:
1717
- matchRegex:
18-
path: data.postgresql\.conf
18+
path: data["postgresql.conf"]
1919
pattern: max_connections = 2000000000000000000
2020
- it: should fail to render when both codeIntelDB.additionalConfig and codeIntelDB.existingConfig are defined
2121
set:

charts/sourcegraph/tests/defaultTagPrefix_test.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ tests:
99
frontend:
1010
image:
1111
defaultTag: test
12-
matchRegexRaw:
13-
path: "spec.template.spec.containers[0].image"
14-
pattern: |
15-
"[\w-]+\.\w+\.\w+\/.+\/.+:test"
12+
asserts:
13+
- matchRegex:
14+
path: "spec.template.spec.containers[0].image"
15+
pattern: ^[\w-]+\.\w+\.\w+\/.+\/.+:test$
1616
- it: should add defaultTagPrefix
1717
template: frontend/sourcegraph-frontend.Deployment.yaml
1818
set:
1919
frontend:
2020
image:
2121
defaultTag: test
2222
defaultTagPrefix: "prefix-"
23-
matchRegexRaw:
24-
path: "spec.template.spec.containers[0].image"
25-
pattern: |
26-
"[\w-]+\.\w+\.\w+\/.+\/.+:prefix-test"
23+
asserts:
24+
- matchRegex:
25+
path: "spec.template.spec.containers[0].image"
26+
pattern: ^[\w-]+\.\w+\.\w+\/.+\/.+:prefix-test$

charts/sourcegraph/tests/localDevMode_test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ tests:
66
set:
77
sourcegraph.localDevMode: true
88
asserts:
9-
- isEmpty:
10-
path: spec.template.spec.containers[0].resources
9+
- notExists:
10+
path: "spec.template.spec.containers[0].resources"
1111

1212
- it: should have a resource block when localDevMode=false
1313
set:
1414
sourcegraph.localDevMode: false
1515
asserts:
16-
- isNotEmpty:
17-
path: spec.template.spec.containers[0].resources
16+
- exists:
17+
path: "spec.template.spec.containers[0].resources"

charts/sourcegraph/tests/nodeExporter_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ tests:
102102
create: false
103103
name: "test-service-account-name"
104104
asserts:
105-
- isEmpty:
105+
- notExists:
106106
path: spec.template.spec.serviceAccountName
107107
template: node-exporter/node-exporter.DaemonSet.yaml
108108

charts/sourcegraph/tests/otelCollectorJaeger_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ tests:
6565
count: 1 # ConfigMap is rendered
6666
template: otel-collector/otel-collector.ConfigMap.yaml
6767
- matchRegex:
68-
path: data.[config.yaml]
68+
path: data["config.yaml"]
6969
pattern: "endpoint: otlp.service.com:443" # check if element of config is substituted correctly
7070
template: otel-collector/otel-collector.ConfigMap.yaml
7171
- it: should fail if a configuration is provided and jaeger is enabled

charts/sourcegraph/tests/pgsqlAdditionalConfig_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tests:
1616
max_connections = 3000000000000000000
1717
asserts:
1818
- matchRegex:
19-
path: data.postgresql\.conf
19+
path: data["postgresql.conf"]
2020
pattern: max_connections = 1000000000000000000
2121
- it: should fail to render when both pgsql.additionalConfig and pgsql.existingConfig are defined
2222
set:

charts/sourcegraph/tests/pgsqlAuth_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tests:
1818
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
1919
value: "my-secret"
2020
- matchSnapshot:
21-
path: spec.template.metadata.annotations.[checksum/pgsql.secret]
21+
path: spec.template.metadata.annotations["checksum/pgsql.secret"]
2222
- it: should not generate a secret when existingSecret is passed
2323
template: pgsql/pgsql.Secret.yaml
2424
set:
@@ -62,4 +62,4 @@ tests:
6262
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
6363
value: "pgsql-auth"
6464
- matchSnapshot:
65-
path: spec.template.metadata.annotations.[checksum/pgsql.secret]
65+
path: spec.template.metadata.annotations["checksum/pgsql.secret"]

0 commit comments

Comments
 (0)