config/module: Child(nil) or empty will return self
This commit is contained in:
parent
267d45df86
commit
1e00b4386c
|
@ -70,7 +70,7 @@ func (t *Tree) Config() *config.Config {
|
|||
// Child returns the child with the given path (by name).
|
||||
func (t *Tree) Child(path []string) *Tree {
|
||||
if len(path) == 0 {
|
||||
return nil
|
||||
return t
|
||||
}
|
||||
|
||||
c := t.Children()[path[0]]
|
||||
|
@ -78,10 +78,6 @@ func (t *Tree) Child(path []string) *Tree {
|
|||
return nil
|
||||
}
|
||||
|
||||
if len(path) == 1 {
|
||||
return c
|
||||
}
|
||||
|
||||
return c.Child(path[1:])
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,20 @@ func TestTreeChild(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Should be able to get the root child
|
||||
if c := tree.Child([]string{}); c == nil {
|
||||
t.Fatal("should not be nil")
|
||||
} else if c.Name() != "root" {
|
||||
t.Fatalf("bad: %#v", c.Name())
|
||||
}
|
||||
|
||||
// Should be able to get the root child
|
||||
if c := tree.Child(nil); c == nil {
|
||||
t.Fatal("should not be nil")
|
||||
} else if c.Name() != "root" {
|
||||
t.Fatalf("bad: %#v", c.Name())
|
||||
}
|
||||
|
||||
// Should be able to get the foo child
|
||||
if c := tree.Child([]string{"foo"}); c == nil {
|
||||
t.Fatal("should not be nil")
|
||||
|
|
Loading…
Reference in New Issue