diff options
author | Vincent Ambo <tazjin@gmail.com> | 2017-07-13T13·57+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2017-07-13T14·07+0200 |
commit | 7607f6dc0fff076cc69ca2d6f50eb04b728e3a44 (patch) | |
tree | 7deafdc7ad291249d773eaec1b47113e843b22a3 /context/context_test.go | |
parent | 9d26c17f13240479ef3e12e9182aca3ac2e61901 (diff) |
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
Diffstat (limited to 'context/context_test.go')
-rw-r--r-- | context/context_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/context/context_test.go b/context/context_test.go index b6acf416e6cc..350b2b66a9cf 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() + } +} |