From b06a0474f88fcf91c8747df2b08ef792c64a44cc Mon Sep 17 00:00:00 2001 From: quobix Date: Thu, 13 Jun 2024 10:32:40 -0400 Subject: [PATCH] Added coverage, removed dead code from path utils --- utils/utils.go | 5 ----- utils/utils_test.go | 11 +++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index c340c14b..d8ff1f7a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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 } diff --git a/utils/utils_test.go b/utils/utils_test.go index 2f6b1568..298d7fbf 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -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)