Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes #988 - Plugins with multiple config policy nodes may cause a pa…
Browse files Browse the repository at this point in the history
…nic (#989)

* Fixes #988 - Plugins with multiple config policy nodes may cause a panic

* Test for #988 - Plugins with multiple config policy nodes may cause a panic
  • Loading branch information
jcooklin authored and tiffanyfay committed Jun 17, 2016
1 parent cc6189c commit 6a8ba3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/ctree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (c *ConfigTree) Get(ns []string) Node {
childNodes := child.get(remain)
*retNodes = append(*retNodes, *childNodes...)
}
if len(*retNodes) == 0 {
// There are no child nodes with configs so we return
return nil
}

c.log(fmt.Sprintf("nodes to merge count (%d)\n", len(*retNodes)))
// Call Node.Merge() sequentially on the retNodes
Expand Down
17 changes: 16 additions & 1 deletion pkg/ctree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestConfigTree(t *testing.T) {
So(g, ShouldNotBeNil)
})

Convey("get is inbetween two nodes in tree", func() {
Convey("get is in between two nodes in tree", func() {
d1 := newMockNode()
d1.data = "a"
d2 := newMockNode()
Expand All @@ -219,6 +219,21 @@ func TestConfigTree(t *testing.T) {
}, ShouldPanic)
})

Convey("doesn't panic on ns where the root and ns don't have a policy", func() {
d1 := newMockNode()
d1.data = "a"
d2 := newMockNode()
d2.data = "b"
c := New()
c.Add([]string{"intel", "foo", "sdi-x", "cody"}, d1)
c.Add([]string{"intel", "foo", "sdi-x", "nan"}, d2)
c.Freeze()
So(func() {
g := c.Get([]string{"intel", "foo", "sdi-x", "emily", "tiffany", "matt"})
So(g, ShouldBeNil)
}, ShouldNotPanic)
})

Convey("doesn't panic on empty ns", func() {
d1 := newMockNode()
d1.data = "a"
Expand Down

0 comments on commit 6a8ba3a

Please sign in to comment.