Added coverage, removed dead code from path utils

This commit is contained in:
quobix
2024-06-13 10:32:40 -04:00
parent cd5601e0d8
commit 65422f0c58
2 changed files with 11 additions and 5 deletions

View File

@@ -702,11 +702,6 @@ func ConvertComponentIdIntoPath(id string) (string, string) {
}
replaced := strings.ReplaceAll(strings.Join(cleaned, "/"), "$", "#")
if len(replaced) > 0 {
if replaced[0] != '#' {
replaced = fmt.Sprintf("#%s", replaced)
}
}
return name, replaced
}

View File

@@ -783,6 +783,11 @@ func TestConvertComponentIdIntoFriendlyPathSearch_Array(t *testing.T) {
assert.Equal(t, "0", segment)
}
func TestConvertComponentIdIntoFriendlyPathSearch_Slashes(t *testing.T) {
_, path := ConvertComponentIdIntoFriendlyPathSearch(`#/nice/\rice/\and/\spice`)
assert.Equal(t, "$.nice.rice.and.spice", path)
}
func TestConvertComponentIdIntoFriendlyPathSearch_HTTPCode(t *testing.T) {
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/paths/~1crazy~1ass~1references/get/responses/404")
assert.Equal(t, "$.paths['/crazy/ass/references'].get.responses['404']", path)
@@ -795,6 +800,12 @@ func TestConvertComponentIdIntoPath(t *testing.T) {
assert.Equal(t, "cake", segment)
}
func TestConvertComponentIdIntoPath_NoHash(t *testing.T) {
segment, path := ConvertComponentIdIntoPath("chicken.chips.pizza.cake")
assert.Equal(t, "#/chicken/chips/pizza/cake", path)
assert.Equal(t, "cake", segment)
}
func TestConvertComponentIdIntoPath_Alt1(t *testing.T) {
segment, path := ConvertComponentIdIntoPath("$.chicken.chips['pizza'].cakes[0].burgers[2]")
assert.Equal(t, "#/chicken/chips/pizza/cakes/0/burgers/2", path)