diff --git a/src/internal/path/path.go b/src/internal/path/path.go index 2ea47c319..efe675fdd 100644 --- a/src/internal/path/path.go +++ b/src/internal/path/path.go @@ -198,6 +198,10 @@ func (pb Builder) String() string { } func (pb Builder) ShortRef() string { + if len(pb.elements) == 0 { + return "" + } + data := bytes.Buffer{} for _, element := range pb.elements { diff --git a/src/internal/path/path_test.go b/src/internal/path/path_test.go index 1af35d019..d90715e7b 100644 --- a/src/internal/path/path_test.go +++ b/src/internal/path/path_test.go @@ -366,9 +366,29 @@ func (suite *PathUnitSuite) TestPopFront() { } func (suite *PathUnitSuite) TestShortRef() { - pb := Builder{}.Append("this", "is", "a", "path") - ref := pb.ShortRef() - assert.Len(suite.T(), ref, shortRefCharacters) + table := []struct { + name string + inputElements []string + expectedLen int + }{ + { + name: "PopulatedPath", + inputElements: []string{"this", "is", "a", "path"}, + expectedLen: shortRefCharacters, + }, + { + name: "EmptyPath", + inputElements: nil, + expectedLen: 0, + }, + } + for _, test := range table { + suite.T().Run(test.name, func(t *testing.T) { + pb := Builder{}.Append(test.inputElements...) + ref := pb.ShortRef() + assert.Len(suite.T(), ref, test.expectedLen) + }) + } } func (suite *PathUnitSuite) TestShortRefIsStable() {