Skip to content

Commit 47492c4

Browse files
authored
Merge pull request #332 from arbourd/add-values-test
2 parents 6f0825c + c0bd4ab commit 47492c4

File tree

5 files changed

+150
-30
lines changed

5 files changed

+150
-30
lines changed

controllers/helmchart_controller_test.go

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ var _ = Describe("HelmChartReconciler", func() {
133133
_ = k8sClient.Get(context.Background(), key, got)
134134
return got.Status.Artifact != nil && storage.ArtifactExist(*got.Status.Artifact)
135135
}, timeout, interval).Should(BeTrue())
136+
helmChart, err := loader.Load(storage.LocalPath(*got.Status.Artifact))
137+
Expect(err).NotTo(HaveOccurred())
138+
Expect(helmChart.Values["testDefault"]).To(BeTrue())
139+
Expect(helmChart.Values["testOverride"]).To(BeFalse())
136140

137141
By("Packaging a new chart version and regenerating the index")
138142
Expect(helmServer.PackageChartWithVersion(path.Join("testdata/charts/helmchart"), "0.2.0")).Should(Succeed())
@@ -585,13 +589,55 @@ var _ = Describe("HelmChartReconciler", func() {
585589
Expect(err).NotTo(HaveOccurred())
586590

587591
By("Expecting new artifact revision and GC")
592+
now := &sourcev1.HelmChart{}
588593
Eventually(func() bool {
589-
now := &sourcev1.HelmChart{}
590594
_ = k8sClient.Get(context.Background(), key, now)
591595
// Test revision change and garbage collection
592596
return now.Status.Artifact.Revision != got.Status.Artifact.Revision &&
593597
!storage.ArtifactExist(*got.Status.Artifact)
594598
}, timeout, interval).Should(BeTrue())
599+
helmChart, err := loader.Load(storage.LocalPath(*now.Status.Artifact))
600+
Expect(err).NotTo(HaveOccurred())
601+
Expect(helmChart.Values["testDefault"]).To(BeTrue())
602+
Expect(helmChart.Values["testOverride"]).To(BeFalse())
603+
604+
When("Setting valid valuesFile attribute", func() {
605+
updated := &sourcev1.HelmChart{}
606+
Expect(k8sClient.Get(context.Background(), key, updated)).To(Succeed())
607+
updated.Spec.ValuesFile = "./testdata/charts/helmchart/override.yaml"
608+
Expect(k8sClient.Update(context.Background(), updated)).To(Succeed())
609+
got := &sourcev1.HelmChart{}
610+
Eventually(func() bool {
611+
_ = k8sClient.Get(context.Background(), key, got)
612+
return got.Status.Artifact.Checksum != updated.Status.Artifact.Checksum &&
613+
storage.ArtifactExist(*got.Status.Artifact)
614+
}, timeout, interval).Should(BeTrue())
615+
f, err := os.Stat(storage.LocalPath(*got.Status.Artifact))
616+
Expect(err).NotTo(HaveOccurred())
617+
Expect(f.Size()).To(BeNumerically(">", 0))
618+
helmChart, err := loader.Load(storage.LocalPath(*got.Status.Artifact))
619+
Expect(err).NotTo(HaveOccurred())
620+
Expect(helmChart.Values["testOverride"]).To(BeTrue())
621+
})
622+
623+
When("Setting invalid valuesFile attribute", func() {
624+
updated := &sourcev1.HelmChart{}
625+
Expect(k8sClient.Get(context.Background(), key, updated)).To(Succeed())
626+
updated.Spec.ValuesFile = "./testdata/charts/helmchart/invalid.yaml"
627+
Expect(k8sClient.Update(context.Background(), updated)).To(Succeed())
628+
got := &sourcev1.HelmChart{}
629+
Eventually(func() bool {
630+
_ = k8sClient.Get(context.Background(), key, got)
631+
return got.Status.ObservedGeneration > updated.Status.ObservedGeneration &&
632+
storage.ArtifactExist(*got.Status.Artifact)
633+
}, timeout, interval).Should(BeTrue())
634+
f, err := os.Stat(storage.LocalPath(*got.Status.Artifact))
635+
Expect(err).NotTo(HaveOccurred())
636+
Expect(f.Size()).To(BeNumerically(">", 0))
637+
helmChart, err := loader.Load(storage.LocalPath(*got.Status.Artifact))
638+
Expect(err).NotTo(HaveOccurred())
639+
Expect(helmChart.Values["testOverride"]).To(BeTrue())
640+
})
595641
})
596642

597643
It("Creates artifacts with .tgz file", func() {
@@ -693,31 +739,6 @@ var _ = Describe("HelmChartReconciler", func() {
693739
return got.Status.Artifact != nil &&
694740
storage.ArtifactExist(*got.Status.Artifact)
695741
}, timeout, interval).Should(BeTrue())
696-
697-
When("Setting valid valuesFile attribute", func() {
698-
updated := &sourcev1.HelmChart{}
699-
Expect(k8sClient.Get(context.Background(), key, updated)).To(Succeed())
700-
chart.Spec.ValuesFile = "./charts/helmchart/override.yaml"
701-
Expect(k8sClient.Update(context.Background(), updated)).To(Succeed())
702-
got := &sourcev1.HelmChart{}
703-
Eventually(func() bool {
704-
_ = k8sClient.Get(context.Background(), key, got)
705-
return got.Status.Artifact != nil &&
706-
storage.ArtifactExist(*got.Status.Artifact)
707-
}, timeout, interval).Should(BeTrue())
708-
})
709-
710-
When("Setting invalid valuesFile attribute", func() {
711-
updated := &sourcev1.HelmChart{}
712-
Expect(k8sClient.Get(context.Background(), key, updated)).To(Succeed())
713-
chart.Spec.ValuesFile = "invalid.yaml"
714-
Expect(k8sClient.Update(context.Background(), updated)).To(Succeed())
715-
got := &sourcev1.HelmChart{}
716-
Eventually(func() bool {
717-
_ = k8sClient.Get(context.Background(), key, got)
718-
return got.Status.Artifact != nil && got.Status.Artifact.Revision == updated.Status.Artifact.Revision
719-
}, timeout, interval).Should(BeTrue())
720-
})
721742
})
722743
})
723744

@@ -961,30 +982,47 @@ var _ = Describe("HelmChartReconciler", func() {
961982
return got.Status.Artifact != nil &&
962983
storage.ArtifactExist(*got.Status.Artifact)
963984
}, timeout, interval).Should(BeTrue())
985+
helmChart, err := loader.Load(storage.LocalPath(*got.Status.Artifact))
986+
Expect(err).NotTo(HaveOccurred())
987+
Expect(helmChart.Values["testDefault"]).To(BeTrue())
988+
Expect(helmChart.Values["testOverride"]).To(BeFalse())
964989

965990
When("Setting valid valuesFile attribute", func() {
966991
updated := &sourcev1.HelmChart{}
967992
Expect(k8sClient.Get(context.Background(), key, updated)).To(Succeed())
968-
chart.Spec.ValuesFile = "override.yaml"
993+
updated.Spec.ValuesFile = "./testdata/charts/helmchartwithdeps/override.yaml"
969994
Expect(k8sClient.Update(context.Background(), updated)).To(Succeed())
970995
got := &sourcev1.HelmChart{}
971996
Eventually(func() bool {
972997
_ = k8sClient.Get(context.Background(), key, got)
973-
return got.Status.Artifact != nil &&
998+
return got.Status.Artifact.Checksum != updated.Status.Artifact.Checksum &&
974999
storage.ArtifactExist(*got.Status.Artifact)
9751000
}, timeout, interval).Should(BeTrue())
1001+
f, err := os.Stat(storage.LocalPath(*got.Status.Artifact))
1002+
Expect(err).NotTo(HaveOccurred())
1003+
Expect(f.Size()).To(BeNumerically(">", 0))
1004+
helmChart, err := loader.Load(storage.LocalPath(*got.Status.Artifact))
1005+
Expect(err).NotTo(HaveOccurred())
1006+
Expect(helmChart.Values["testOverride"]).To(BeTrue())
9761007
})
9771008

9781009
When("Setting invalid valuesFile attribute", func() {
9791010
updated := &sourcev1.HelmChart{}
9801011
Expect(k8sClient.Get(context.Background(), key, updated)).To(Succeed())
981-
chart.Spec.ValuesFile = "./charts/helmchart/override.yaml"
1012+
updated.Spec.ValuesFile = "./testdata/charts/helmchartwithdeps/invalid.yaml"
9821013
Expect(k8sClient.Update(context.Background(), updated)).To(Succeed())
9831014
got := &sourcev1.HelmChart{}
9841015
Eventually(func() bool {
9851016
_ = k8sClient.Get(context.Background(), key, got)
986-
return got.Status.Artifact != nil && got.Status.Artifact.Revision == updated.Status.Artifact.Revision
1017+
return got.Status.ObservedGeneration > updated.Status.ObservedGeneration &&
1018+
storage.ArtifactExist(*got.Status.Artifact)
9871019
}, timeout, interval).Should(BeTrue())
1020+
f, err := os.Stat(storage.LocalPath(*got.Status.Artifact))
1021+
Expect(err).NotTo(HaveOccurred())
1022+
Expect(f.Size()).To(BeNumerically(">", 0))
1023+
helmChart, err := loader.Load(storage.LocalPath(*got.Status.Artifact))
1024+
Expect(err).NotTo(HaveOccurred())
1025+
Expect(helmChart.Values["testOverride"]).To(BeTrue())
9881026
})
9891027
})
9901028
})

controllers/testdata/charts/helmchart/override.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ nodeSelector: {}
6464
tolerations: []
6565

6666
affinity: {}
67+
68+
# Values for tests
69+
# testDefault: true
70+
testOverride: true

controllers/testdata/charts/helmchart/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ nodeSelector: {}
6464
tolerations: []
6565

6666
affinity: {}
67+
68+
# Values for tests
69+
testDefault: true
70+
testOverride: false
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Override values for helmchart.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
replicaCount: 3
6+
7+
image:
8+
repository: nginx
9+
pullPolicy: IfNotPresent
10+
11+
imagePullSecrets: []
12+
nameOverride: ""
13+
fullnameOverride: ""
14+
15+
serviceAccount:
16+
# Specifies whether a service account should be created
17+
create: true
18+
# The name of the service account to use.
19+
# If not set and create is true, a name is generated using the fullname template
20+
name:
21+
22+
podSecurityContext: {}
23+
# fsGroup: 2000
24+
25+
securityContext: {}
26+
# capabilities:
27+
# drop:
28+
# - ALL
29+
# readOnlyRootFilesystem: true
30+
# runAsNonRoot: true
31+
# runAsUser: 1000
32+
33+
service:
34+
type: ClusterIP
35+
port: 80
36+
37+
ingress:
38+
enabled: false
39+
annotations: {}
40+
# kubernetes.io/ingress.class: nginx
41+
# kubernetes.io/tls-acme: "true"
42+
hosts:
43+
- host: chart-example.local
44+
paths: []
45+
tls: []
46+
# - secretName: chart-example-tls
47+
# hosts:
48+
# - chart-example.local
49+
50+
resources: {}
51+
# We usually recommend not to specify default resources and to leave this as a conscious
52+
# choice for the user. This also increases chances charts run on environments with little
53+
# resources, such as Minikube. If you do want to specify resources, uncomment the following
54+
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
55+
# limits:
56+
# cpu: 100m
57+
# memory: 128Mi
58+
# requests:
59+
# cpu: 100m
60+
# memory: 128Mi
61+
62+
nodeSelector: {}
63+
64+
tolerations: []
65+
66+
affinity: {}
67+
68+
# Values for tests
69+
# testDefault: true
70+
testOverride: true

controllers/testdata/charts/helmchartwithdeps/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ nodeSelector: {}
6464
tolerations: []
6565

6666
affinity: {}
67+
68+
# Values for tests
69+
testDefault: true
70+
testOverride: false

0 commit comments

Comments
 (0)