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
This commit is contained in:
Vincent Ambo 2017-07-13 15:57:18 +02:00
parent 9d26c17f13
commit 7607f6dc0f
4 changed files with 105 additions and 5 deletions

View file

@ -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()
}
}