Empty path generates empty short ref (#868)
## Description Fixup corner case on ShortRef so that empty paths generate the empty string. This makes some cases with generating short refs for each parent path to an item easier because the base case (empty path) is no different than other cases. <!-- Insert PR description--> ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [x] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🐹 Trivial/Minor ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * part of #818 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
7cbee2bf58
commit
6d5540cdf6
@ -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 {
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user