config/module: tree.Child on a nil tree works
This commit is contained in:
parent
ba751c4e3b
commit
55ef966b88
|
@ -66,6 +66,10 @@ func (t *Tree) Config() *config.Config {
|
||||||
|
|
||||||
// Child returns the child with the given path (by name).
|
// Child returns the child with the given path (by name).
|
||||||
func (t *Tree) Child(path []string) *Tree {
|
func (t *Tree) Child(path []string) *Tree {
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(path) == 0 {
|
if len(path) == 0 {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTreeChild(t *testing.T) {
|
func TestTreeChild(t *testing.T) {
|
||||||
|
var nilTree *Tree
|
||||||
|
if nilTree.Child(nil) != nil {
|
||||||
|
t.Fatal("child should be nil")
|
||||||
|
}
|
||||||
|
|
||||||
storage := testStorage(t)
|
storage := testStorage(t)
|
||||||
tree := NewTree("", testConfig(t, "child"))
|
tree := NewTree("", testConfig(t, "child"))
|
||||||
if err := tree.Load(storage, GetModeGet); err != nil {
|
if err := tree.Load(storage, GetModeGet); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue