config/module: tree.Child on a nil tree works

This commit is contained in:
Mitchell Hashimoto 2016-09-14 13:35:54 -07:00
parent ba751c4e3b
commit 55ef966b88
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 9 additions and 0 deletions

View File

@ -66,6 +66,10 @@ func (t *Tree) Config() *config.Config {
// Child returns the child with the given path (by name).
func (t *Tree) Child(path []string) *Tree {
if t == nil {
return nil
}
if len(path) == 0 {
return t
}

View File

@ -12,6 +12,11 @@ import (
)
func TestTreeChild(t *testing.T) {
var nilTree *Tree
if nilTree.Child(nil) != nil {
t.Fatal("child should be nil")
}
storage := testStorage(t)
tree := NewTree("", testConfig(t, "child"))
if err := tree.Load(storage, GetModeGet); err != nil {