Skip to content

Commit

Permalink
Proposal: add unit tests (#138)
Browse files Browse the repository at this point in the history
* Proposal: add basic unittest

* I had that all sorts of wrong

* right need a version bump

---------

Signed-off-by: Don O'Neill <[email protected]>
  • Loading branch information
sntxrr authored Oct 28, 2023
1 parent c32332b commit 0c7119d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ helm repo add opencost https://opencost.github.io/opencost-helm-chart

See the [Chart Documentation](https://github.com/opencost/opencost-helm-chart/blob/main/charts/opencost/README.md) for chart install instructions.

## Testing

[Testing](https://github.com/helm-unittest/helm-unittest) your chart (optional)

Presumes you've got Helm unittest installed: (i.e. `helm plugin install unittest`) and that your in the root directory of your cloned repo:

```console
helm unittest charts/opencost
```
Should produce a result like this:

```
### Chart [ opencost ] charts/opencost
PASS test deployment charts/opencost/tests/deployment_test.yaml
PASS test deployment snapshot charts/opencost/tests/opencost_test.yaml
Charts: 1 passed, 1 total
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshot: 1 passed, 1 total
Time: 31.011089ms
```

***

## OpenCost Links
* [OpenCost](https://github.com/opencost/opencost)
* [Documentation](https://www.opencost.io/docs/)
2 changes: 1 addition & 1 deletion charts/opencost/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords:
- kubecost
- opencost
- monitoring
version: 1.22.1
version: 1.22.2
maintainers:
- name: mattray
url: https://mattray.dev
Expand Down
16 changes: 16 additions & 0 deletions charts/opencost/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
suite: test deployment
templates:
- templates/deployment.yaml
tests:
- it: should work
set:
image.tag: latest
asserts:
- isKind:
of: Deployment
- matchRegex:
path: metadata.name
pattern: -opencost$
- matchRegex:
path: spec.template.spec.containers[0].image
pattern: quay\.io\/kubecost1\/kubecost-cost-model:prod-[0-9]*\.[0-9]*\.[0-9]*
7 changes: 7 additions & 0 deletions charts/opencost/tests/opencost_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
suite: test deployment snapshot
templates:
- templates/deployment.yaml
tests:
- it: pod spec should match snapshot
asserts:
- matchSnapshot: {}

0 comments on commit 0c7119d

Please sign in to comment.