summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/helm/helm_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/internal/helm/helm_test.go')
-rw-r--r--src/k8splugin/internal/helm/helm_test.go67
1 files changed, 47 insertions, 20 deletions
diff --git a/src/k8splugin/internal/helm/helm_test.go b/src/k8splugin/internal/helm/helm_test.go
index 358577ea..29d446fa 100644
--- a/src/k8splugin/internal/helm/helm_test.go
+++ b/src/k8splugin/internal/helm/helm_test.go
@@ -20,6 +20,7 @@ package helm
import (
"crypto/sha256"
"fmt"
+ "gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
"strings"
@@ -45,7 +46,7 @@ func TestProcessValues(t *testing.T) {
filepath.Join(profileDir, "override_values.yaml"),
},
//Hash of a combined values.yaml file that is expected
- expectedHash: "c18a70f426933de3c051c996dc34fd537d0131b2d13a2112a2ecff674db6c2f9",
+ expectedHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
expectedError: "",
},
{
@@ -58,7 +59,7 @@ func TestProcessValues(t *testing.T) {
"service.externalPort=82",
},
//Hash of a combined values.yaml file that is expected
- expectedHash: "028a3521fc9f8777ea7e67a6de0c51f2c875b88ca91734999657f0ca924ddb7a",
+ expectedHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
expectedError: "",
},
{
@@ -73,7 +74,7 @@ func TestProcessValues(t *testing.T) {
"service.externalPort=82",
},
//Hash of a combined values.yaml file that is expected
- expectedHash: "516fab4ab7b76ba2ff35a97c2a79b74302543f532857b945f2fe25e717e755be",
+ expectedHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
expectedError: "",
},
{
@@ -83,7 +84,7 @@ func TestProcessValues(t *testing.T) {
"servers[0].port=80",
},
expectedError: "",
- expectedHash: "50d9401b003f65c1ccfd1c5155106fff88c8201ab8b7d66bd6ffa4fe2883bead",
+ expectedHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
}
@@ -102,11 +103,11 @@ func TestProcessValues(t *testing.T) {
}
} else {
//Compute the hash of returned data and compare
- h.Write(out)
gotHash := fmt.Sprintf("%x", h.Sum(nil))
h.Reset()
if gotHash != testCase.expectedHash {
- t.Fatalf("Got unexpected hash '%s' of values.yaml:\n%s", gotHash, out)
+ mout, _ := yaml.Marshal(&out)
+ t.Fatalf("Got unexpected hash '%s' of values.yaml:\n%v", gotHash, string(mout))
}
}
})
@@ -133,9 +134,9 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
values: []string{},
//sha256 hash of the evaluated templates in each chart
expectedHashMap: map[string]string{
- "testchart2/templates/service.yaml": "fdd6a2b6795486f0dd1d8c44379afb5ffe4072c09f9cf6594738e8ded4dd872d",
- "subcharta/templates/service.yaml": "570389588fffdb7193ab265888d781f3d751f3a40362533344f9aa7bb93a8bb0",
- "subchartb/templates/service.yaml": "5654e03d922e8ec49649b4bbda9dfc9e643b3b7c9c18b602cc7e26fd36a39c2a",
+ "manifest-0": "fcc1083ace82b633e3a0a687d50f532c07e1212b7a42b2c178b65e5768fffcfe",
+ "manifest-2": "eefeac6ff5430a16a32ae3974857cbe5ff516a1a68566e5edcddd410d60397c0",
+ "manifest-1": "b88aa963ee3afb9676e9930519d7caa103df1251da48a9351ab4ac0c5730d2af",
},
expectedError: "",
},
@@ -150,9 +151,9 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
},
//sha256 hash of the evaluated templates in each chart
expectedHashMap: map[string]string{
- "testchart2/templates/service.yaml": "2bb96e791ecb6a3404bc5de3f6c4182aed881630269e2aa6766df38b0f852724",
- "subcharta/templates/service.yaml": "570389588fffdb7193ab265888d781f3d751f3a40362533344f9aa7bb93a8bb0",
- "subchartb/templates/service.yaml": "5654e03d922e8ec49649b4bbda9dfc9e643b3b7c9c18b602cc7e26fd36a39c2a",
+ "manifest-0": "fcc1083ace82b633e3a0a687d50f532c07e1212b7a42b2c178b65e5768fffcfe",
+ "manifest-2": "03ae530e49071d005be78f581b7c06c59119f91f572b28c0c0c06ced8e37bf6e",
+ "manifest-1": "b88aa963ee3afb9676e9930519d7caa103df1251da48a9351ab4ac0c5730d2af",
},
expectedError: "",
},
@@ -164,8 +165,8 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
"goingEmpty=false",
},
expectedHashMap: map[string]string{
- "testchart3/templates/multi.yaml-2": "e24cbbefac2c2f700880b8fd041838f2dd48bbc1e099e7c1d2485ae7feb3da0d",
- "testchart3/templates/multi.yaml-3": "592a8e5b2c35b8469aa45703a835bc00657bfe36b51eb08427a46e7d22fb1525",
+ "manifest-0": "666e8d114981a4b5d13fb799be060aa57e0e48904bba4a410f87a2e827a57ddb",
+ "manifest-2": "6a5af22538c273b9d4a3156e3b6bb538c655041eae31e93db21a9e178f73ecf0",
},
expectedError: "",
},
@@ -177,9 +178,9 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
"goingEmpty=true",
},
expectedHashMap: map[string]string{
- "testchart3/templates/multi.yaml-3": "e24cbbefac2c2f700880b8fd041838f2dd48bbc1e099e7c1d2485ae7feb3da0d",
- "testchart3/templates/multi.yaml-4": "0bea01e65148584609ede5000c024241ba1c35b440b32ec0a4f7013015715bfe",
- "testchart3/templates/multi.yaml-5": "6a5af22538c273b9d4a3156e3b6bb538c655041eae31e93db21a9e178f73ecf0",
+ "manifest-0": "666e8d114981a4b5d13fb799be060aa57e0e48904bba4a410f87a2e827a57ddb",
+ "manifest-1": "8613e7e7cc0186516b13be37ec7fc321ff89e3abaed0a841773a4eba2d77ce2a",
+ "manifest-2": "3543ae9563fe62ce4a7446d72e1cd23140d8cc5495f0221430d70e94845c1408",
},
expectedError: "",
},
@@ -190,7 +191,8 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
values: []string{},
expectedError: "",
expectedHashMap: map[string]string{
- "mockv3/templates/deployment.yaml": "259a027a4957e7428eb1d2e774fa1afaa62449521853f8b2916887040bae2ca4",
+ "manifest-0": "94975ff704b9cc00a7988fe7fc865665495655ec2584d3e9de2f7e5294c7eb0d",
+ "dummy-test": "b50bb5f818fe0be332f09401104ae9cea59442e2dabe1a16b4ce21b753177a80",
},
},
}
@@ -200,7 +202,7 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
tc := NewTemplateClient("1.12.3", "testnamespace", "testreleasename")
- out, _, err := tc.GenerateKubernetesArtifacts(testCase.chartPath, testCase.valueFiles,
+ out, hooks, err := tc.GenerateKubernetesArtifacts(testCase.chartPath, testCase.valueFiles,
testCase.values)
if err != nil {
if testCase.expectedError == "" {
@@ -209,13 +211,38 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
if strings.Contains(err.Error(), testCase.expectedError) == false {
t.Fatalf("Got unexpected error message %s", err)
}
+ } else if len(testCase.expectedHashMap) != len(out)+len(hooks) {
+ t.Fatalf("Mismatch of expected files (%d) and returned resources (%d)",
+ len(testCase.expectedHashMap), len(out)+len(hooks))
} else {
//Compute the hash of returned data and compare
for _, v := range out {
f := v.FilePath
data, err := ioutil.ReadFile(f)
if err != nil {
- t.Errorf("Unable to read file %s", v)
+ t.Fatalf("Unable to read file %s", v)
+ }
+ h.Write(data)
+ gotHash := fmt.Sprintf("%x", h.Sum(nil))
+ h.Reset()
+
+ //Find the right hash from expectedHashMap
+ expectedHash := ""
+ for k1, v1 := range testCase.expectedHashMap {
+ if strings.Contains(f, k1) == true {
+ expectedHash = v1
+ break
+ }
+ }
+ if gotHash != expectedHash {
+ t.Fatalf("Got unexpected hash for %s: '%s'; expected: '%s'", f, gotHash, expectedHash)
+ }
+ }
+ for _, v := range hooks {
+ f := v.KRT.FilePath
+ data, err := ioutil.ReadFile(f)
+ if err != nil {
+ t.Fatalf("Unable to read file %+v", v)
}
h.Write(data)
gotHash := fmt.Sprintf("%x", h.Sum(nil))