diff --git a/pkg/chamber_test.go b/pkg/chamber_test.go index 346d67d..19aecc9 100644 --- a/pkg/chamber_test.go +++ b/pkg/chamber_test.go @@ -14,10 +14,14 @@ func TestFindByName(t *testing.T) { bottom, }, } + middle2 := &Chamber{ + Name: "MIDDLE2", + } top := &Chamber{ Name: "TOP", Children: []*Chamber{ middle, + middle2, }, } @@ -27,6 +31,7 @@ func TestFindByName(t *testing.T) { }{ {"BOTTOM", bottom}, {"MIDDLE", middle}, + {"MIDDLE2", middle2}, {"TOP", top}, } @@ -37,3 +42,45 @@ func TestFindByName(t *testing.T) { } } } + +func TestInheritWith(t *testing.T) { + + bottom := &Chamber{ + Name: "BOTTOM", + Toggles: map[string]*Toggle{ + "toggle2": &Toggle{ + Name: "toggle1", + ToggleType: "boolean", + Value: false, + }, + }, + } + top := &Chamber{ + Name: "TOP", + Toggles: map[string]*Toggle{ + "toggle1": &Toggle{ + Name: "toggle1", + ToggleType: "boolean", + Value: false, + }, + }, + } + middle := &Chamber{ + Name: "MIDDLE", + Toggles: map[string]*Toggle{ + "toggle1": &Toggle{ + Name: "toggle1", + ToggleType: "boolean", + Value: false, + }, + }, + } + + middle.InheritWith(top.Toggles) + // should not inherit an already existent key + bottom.InheritWith(middle.Toggles) + + if len(bottom.Toggles) != 2 { + t.Errorf("%q did not inherit properly from %q", bottom.Name, top.Name) + } +}