about summary refs log tree commit diff
path: root/context/context_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'context/context_test.go')
-rw-r--r--context/context_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/context/context_test.go b/context/context_test.go
index b6acf416e6..350b2b66a9 100644
--- a/context/context_test.go
+++ b/context/context_test.go
@@ -21,6 +21,7 @@ func TestLoadFlatContextFromFile(t *testing.T) {
 		ResourceSets: []ResourceSet{
 			{
 				Name: "some-api",
+				Path: "some-api",
 				Values: map[string]interface{}{
 					"apiPort":          float64(4567), // yep!
 					"importantFeature": true,
@@ -55,6 +56,7 @@ func TestLoadContextWithResourceSetCollections(t *testing.T) {
 		ResourceSets: []ResourceSet{
 			{
 				Name: "some-api",
+				Path: "some-api",
 				Values: map[string]interface{}{
 					"apiPort":          float64(4567), // yep!
 					"importantFeature": true,
@@ -65,6 +67,7 @@ func TestLoadContextWithResourceSetCollections(t *testing.T) {
 			},
 			{
 				Name: "collection/nested",
+				Path: "collection/nested",
 				Values: map[string]interface{}{
 					"lizards": "good",
 				},
@@ -95,6 +98,7 @@ func TestSubresourceVariableInheritance(t *testing.T) {
 		ResourceSets: []ResourceSet{
 			{
 				Name: "parent/child",
+				Path: "parent/child",
 				Values: map[string]interface{}{
 					"foo": "bar",
 					"bar": "baz",
@@ -125,6 +129,7 @@ func TestSubresourceVariableInheritanceOverride(t *testing.T) {
 		ResourceSets: []ResourceSet{
 			{
 				Name: "parent/child",
+				Path: "parent/child",
 				Values: map[string]interface{}{
 					"foo": "newvalue",
 				},
@@ -203,3 +208,66 @@ func TestImportValuesOverride(t *testing.T) {
 		t.Fail()
 	}
 }
+
+func TestExplicitPathLoading(t *testing.T) {
+	ctx, err := LoadContextFromFile("testdata/explicit-path.yaml")
+	if err != nil {
+		t.Error(err)
+		t.Fail()
+	}
+
+	expected := Context{
+		Name: "k8s.prod.mydomain.com",
+		ResourceSets: []ResourceSet{
+			{
+				Name: "some-api-europe",
+				Path: "some-api",
+				Values: map[string]interface{}{
+					"location": "europe",
+				},
+				Include: nil,
+				Parent:  "",
+			},
+			{
+				Name: "some-api-asia",
+				Path: "some-api",
+				Values: map[string]interface{}{
+					"location": "asia",
+				},
+				Include: nil,
+				Parent:  "",
+			},
+		},
+		BaseDir: "testdata",
+	}
+
+	if !reflect.DeepEqual(*ctx, expected) {
+		t.Error("Loaded context and expected context did not match")
+		t.Fail()
+	}
+}
+
+func TestExplicitSubresourcePathLoading(t *testing.T) {
+	ctx, err := LoadContextFromFile("testdata/explicit-subresource-path.yaml")
+	if err != nil {
+		t.Error(err)
+		t.Fail()
+	}
+
+	expected := Context{
+		Name: "k8s.prod.mydomain.com",
+		ResourceSets: []ResourceSet{
+			{
+				Name:   "parent/child",
+				Path:   "parent-path/child-path",
+				Parent: "parent",
+			},
+		},
+		BaseDir: "testdata",
+	}
+
+	if !reflect.DeepEqual(*ctx, expected) {
+		t.Error("Loaded context and expected context did not match")
+		t.Fail()
+	}
+}