mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 20:47:45 +00:00
Fix lint issues in util
Reduce execution time of ConvertComponentIdIntoFriendlyPathSearch by 50-60% and add benchmark Signed-off-by: Nicholas Jackson <nickajacks1@gmail.com>
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type petstore []byte
|
||||
@@ -168,8 +169,7 @@ func TestConvertInterfaceToStringArray_NoType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConvertInterfaceToStringArray_Invalid(t *testing.T) {
|
||||
var d interface{}
|
||||
d = "I am a carrot"
|
||||
var d interface{} = "I am a carrot"
|
||||
parsed := ConvertInterfaceToStringArray(d)
|
||||
assert.Nil(t, parsed)
|
||||
}
|
||||
@@ -195,8 +195,7 @@ func TestConvertInterfaceArrayToStringArray_NoType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConvertInterfaceArrayToStringArray_Invalid(t *testing.T) {
|
||||
var d interface{}
|
||||
d = "weed is good"
|
||||
var d interface{} = "weed is good"
|
||||
parsed := ConvertInterfaceArrayToStringArray(d)
|
||||
assert.Nil(t, parsed)
|
||||
}
|
||||
@@ -229,12 +228,11 @@ func TestExtractValueFromInterfaceMap_Flat(t *testing.T) {
|
||||
m["maddy"] = "niblet"
|
||||
d = m
|
||||
parsed := ExtractValueFromInterfaceMap("maddy", d)
|
||||
assert.Equal(t, "niblet", parsed.(interface{}))
|
||||
assert.Equal(t, "niblet", parsed)
|
||||
}
|
||||
|
||||
func TestExtractValueFromInterfaceMap_NotFound(t *testing.T) {
|
||||
var d interface{}
|
||||
d = "not a map"
|
||||
var d interface{} = "not a map"
|
||||
parsed := ExtractValueFromInterfaceMap("melody", d)
|
||||
assert.Nil(t, parsed)
|
||||
}
|
||||
@@ -686,6 +684,14 @@ func TestConvertComponentIdIntoFriendlyPathSearch_Crazy(t *testing.T) {
|
||||
assert.Equal(t, "expires_at", segment)
|
||||
}
|
||||
|
||||
func BenchmarkConvertComponentIdIntoFriendlyPathSearch_Crazy(t *testing.B) {
|
||||
for n := 0; n < t.N; n++ {
|
||||
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/components/schemas/gpg-key/properties/subkeys/example/0/expires_at")
|
||||
assert.Equal(t, "$.components.schemas.gpg-key.properties.subkeys.example[0].expires_at", path)
|
||||
assert.Equal(t, "expires_at", segment)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertComponentIdIntoFriendlyPathSearch_Simple(t *testing.T) {
|
||||
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/~1fresh~1pizza/get")
|
||||
assert.Equal(t, "$['/fresh/pizza'].get", path)
|
||||
|
||||
Reference in New Issue
Block a user