Skip to content

Commit b9ac27f

Browse files
authored
feat: add unit tests for Helm chart (#158)
1 parent 41c4b31 commit b9ac27f

File tree

7 files changed

+1807
-1
lines changed

7 files changed

+1807
-1
lines changed

.helmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ kube-linter.yaml
88
Makefile
99
README.md.gotmpl
1010
scripts
11+
tests

scripts/install_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ curl_flags=(
1818
run_trace false sudo apt-get install --no-install-recommends --yes \
1919
shellcheck
2020

21-
run_trace false curl "${curl_flags[@]}" "https://get.helm.sh/helm-v3.6.0-linux-amd64.tar.gz" \| \
21+
run_trace false curl "${curl_flags[@]}" "https://get.helm.sh/helm-v3.7.1-linux-amd64.tar.gz" \| \
2222
tar -C "$TMPDIR" --strip-components=1 -zxf - linux-amd64/helm
2323

2424
run_trace false curl "${curl_flags[@]}" "https://github.com/norwoodj/helm-docs/releases/download/v1.5.0/helm-docs_1.5.0_Linux_x86_64.tar.gz" \| \

tests/defaults_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
"helm.sh/helm/v3/pkg/chart/loader"
8+
)
9+
10+
// TestDefault loads the chart and checks metadata.
11+
func TestDefault(t *testing.T) {
12+
t.Parallel()
13+
14+
chart, err := loader.LoadDir("..")
15+
require.NoError(t, err, "loaded chart successfully")
16+
require.NotNil(t, chart, "chart must be non-nil")
17+
require.True(t, chart.IsRoot(), "chart must be a root chart")
18+
require.NoError(t, chart.Validate(), "chart has valid metadata")
19+
20+
metadata := chart.Metadata
21+
require.Equal(t, "coder", metadata.Name, "unexpected chart name")
22+
require.False(t, metadata.Deprecated, "chart should not be deprecated")
23+
24+
values, err := ConvertMapToCoderValues(chart.Values, false)
25+
require.NoError(t, err, "converted map to coder values")
26+
require.NotNil(t, values, "values must be non-nil")
27+
coderd := values.Coderd
28+
require.Equal(t, 1, *coderd.Replicas, "expected 1 replica by default")
29+
}

tests/go.mod

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module cdr.dev/enterprise-helm/tests
2+
3+
go 1.17
4+
5+
require (
6+
github.com/stretchr/testify v1.7.0
7+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
8+
helm.sh/helm/v3 v3.7.1
9+
k8s.io/api v0.22.1
10+
k8s.io/apimachinery v0.22.1
11+
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
12+
)
13+
14+
require (
15+
github.com/BurntSushi/toml v0.3.1 // indirect
16+
github.com/Masterminds/goutils v1.1.1 // indirect
17+
github.com/Masterminds/semver/v3 v3.1.1 // indirect
18+
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
19+
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
20+
github.com/davecgh/go-spew v1.1.1 // indirect
21+
github.com/go-logr/logr v0.4.0 // indirect
22+
github.com/gobwas/glob v0.2.3 // indirect
23+
github.com/gogo/protobuf v1.3.2 // indirect
24+
github.com/golang/protobuf v1.5.2 // indirect
25+
github.com/google/go-cmp v0.5.5 // indirect
26+
github.com/google/gofuzz v1.1.0 // indirect
27+
github.com/google/uuid v1.2.0 // indirect
28+
github.com/googleapis/gnostic v0.5.5 // indirect
29+
github.com/huandu/xstrings v1.3.2 // indirect
30+
github.com/imdario/mergo v0.3.12 // indirect
31+
github.com/json-iterator/go v1.1.11 // indirect
32+
github.com/mitchellh/copystructure v1.1.1 // indirect
33+
github.com/mitchellh/reflectwalk v1.0.1 // indirect
34+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
35+
github.com/modern-go/reflect2 v1.0.1 // indirect
36+
github.com/pkg/errors v0.9.1 // indirect
37+
github.com/pmezard/go-difflib v1.0.0 // indirect
38+
github.com/shopspring/decimal v1.2.0 // indirect
39+
github.com/spf13/cast v1.3.1 // indirect
40+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
41+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
42+
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
43+
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
44+
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
45+
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
46+
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
47+
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
48+
golang.org/x/text v0.3.6 // indirect
49+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
50+
google.golang.org/appengine v1.6.7 // indirect
51+
google.golang.org/protobuf v1.26.0 // indirect
52+
gopkg.in/inf.v0 v0.9.1 // indirect
53+
gopkg.in/yaml.v2 v2.4.0 // indirect
54+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
55+
k8s.io/apiextensions-apiserver v0.22.1 // indirect
56+
k8s.io/client-go v0.22.1 // indirect
57+
k8s.io/klog/v2 v2.9.0 // indirect
58+
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
59+
sigs.k8s.io/yaml v1.2.0 // indirect
60+
)

0 commit comments

Comments
 (0)