From 55ef966b88223a46ed51f37f11bd73b1a4791510 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Sep 2016 13:35:54 -0700 Subject: [PATCH] config/module: tree.Child on a nil tree works --- config/module/tree.go | 4 ++++ config/module/tree_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/config/module/tree.go b/config/module/tree.go index a0818bfa4..8a322650b 100644 --- a/config/module/tree.go +++ b/config/module/tree.go @@ -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 } diff --git a/config/module/tree_test.go b/config/module/tree_test.go index f455c2a02..d46d5ed27 100644 --- a/config/module/tree_test.go +++ b/config/module/tree_test.go @@ -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 {