From 7607f6dc0fff076cc69ca2d6f50eb04b728e3a44 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 13 Jul 2017 15:57:18 +0200 Subject: feat context: Allow overriding resource set paths Instead of always inferring the path at which files in a resource set are located, let users override the path by specifying a `path` field. This makes it possible to add the same resource set multiple times with different values while still keeping distinct names for addressability (for example when using include/exclude). This fixes #70 --- context/context_test.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'context/context_test.go') 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() + } +} -- cgit 1.4.1