-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9d8314
commit ee81b84
Showing
5 changed files
with
189 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
['rootCmd fail including dynamic outputs should fail 1'] | ||
SnapShot = 'snapshot does not match chart=example/app1 values=' | ||
|
||
['rootCmd fail invalid flag should fail 1'] | ||
SnapShot = 'unknown flag: --invalid' | ||
|
||
['rootCmd fail required flag is not set should fail 1'] | ||
SnapShot = 'required flag(s) "chart" not set' | ||
|
||
['rootCmd fail snapshot is different should fail 1'] | ||
SnapShot = 'snapshot does not match chart=example/app1 values=example/app1/testfail/test_ingress_enabled.yaml' | ||
|
||
['rootCmd fail values directory contains not matched snapshots should fail 1'] | ||
SnapShot = 'snapshot does not match chart=example/app1 values=example/app1/testfail/test_ingress_enabled.yaml' | ||
|
||
['rootCmd fail values file not found should fail 1'] | ||
SnapShot = """ | ||
values file 'example/app1/test/notfound.yaml' not found""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/jlandowner/helm-chartsnap/pkg/snap/gomega" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Main Suite") | ||
} | ||
|
||
var _ = Describe("rootCmd", func() { | ||
BeforeEach(func() { | ||
initRootCmd() | ||
}) | ||
Context("success", func() { | ||
Context("snapshot local chart with single values file", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "-f", "example/app1/test/test_ingress_enabled.yaml", "--namespace", "default"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot local chart with values directory", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "-f", "example/app1/test/", "--namespace", "default"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot OCI chart", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "oci://ghcr.io/nginxinc/charts/nginx-gateway-fabric", "-f", "example/remote/nginx-gateway-fabric.values.yaml", "--", "--namespace", "nginx-gateway"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot remote chart 1", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "cilium", "-f", "example/remote/cilium.values.yaml", "--", "--namespace", "kube-system", "--repo", "https://helm.cilium.io"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot remote chart 2", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "ingress-nginx", "-f", "example/remote/ingress-nginx.values.yaml", "--", "--namespace", "ingress-nginx", "--repo", "https://kubernetes.github.io/ingress-nginx", "--skip-tests"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot empty chart", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app2", "--namespace", "default"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot empty chart with no config file", func() { | ||
It("should pass", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app2", "--namespace", "default", "--config-file", "notfound"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("snapshot empty chart with debug mode", func() { | ||
It("should pass", func() { | ||
os.Setenv("HELM_DEBUG", "true") | ||
defer os.Unsetenv("HELM_DEBUG") | ||
rootCmd.SetArgs([]string{"--chart", "example/app2", "--namespace", "default"}) | ||
err := rootCmd.Execute() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
|
||
Context("fail", func() { | ||
Context("including dynamic outputs", func() { | ||
It("should fail", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "--namespace", "default"}) | ||
err := rootCmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Ω(err.Error()).To(MatchSnapShot()) | ||
}) | ||
}) | ||
|
||
Context("snapshot is different", func() { | ||
It("should fail", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "--namespace", "default", "-f", "example/app1/testfail/test_ingress_enabled.yaml"}) | ||
err := rootCmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Ω(err.Error()).To(MatchSnapShot()) | ||
}) | ||
}) | ||
|
||
Context("values directory contains not matched snapshots", func() { | ||
It("should fail", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "--namespace", "default", "-f", "example/app1/testfail"}) | ||
err := rootCmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Ω(err.Error()).To(MatchSnapShot()) | ||
}) | ||
}) | ||
|
||
Context("values file not found", func() { | ||
It("should fail", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "-f", "example/app1/test/notfound.yaml", "--namespace", "default"}) | ||
err := rootCmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Ω(err.Error()).To(MatchSnapShot()) | ||
}) | ||
}) | ||
|
||
Context("required flag is not set", func() { | ||
It("should fail", func() { | ||
rootCmd.SetArgs([]string{}) | ||
err := rootCmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Ω(err.Error()).To(MatchSnapShot()) | ||
}) | ||
}) | ||
|
||
Context("invalid flag", func() { | ||
It("should fail", func() { | ||
rootCmd.SetArgs([]string{"--chart", "example/app1", "-f", "example/app1/test/test_ingress_enabled.yaml", "--namespace", "default", "--invalid"}) | ||
err := rootCmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Ω(err.Error()).To(MatchSnapShot()) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters