Skip to content

Commit

Permalink
Added coverage, removed dead code from path utils
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Jun 13, 2024
1 parent 40e71fd commit b06a047
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 0 additions & 5 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit b06a047

Please sign in to comment.