Auth: Replace jmespath/go-jmespath with jmespath-community/go-jmespath (#94203)

Replace jmespath/go-jmespath with jmespath-community/go-jmespath
This commit is contained in:
Misi
2024-10-03 15:43:15 +02:00
committed by GitHub
parent f92ef0e126
commit ee8bb63d2d
4 changed files with 38 additions and 3 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ package util
import (
"encoding/json"
"github.com/jmespath/go-jmespath"
"github.com/jmespath-community/go-jmespath"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
)
@@ -86,7 +86,7 @@ func searchJSONForAttr(attributePath string, data any) (any, error) {
}
// Copy the data to a new variable
var jsonData = data
jsonData := data
// If the data is a byte slice, try to unmarshal it into a JSON object
if dataBytes, ok := data.([]byte); ok {
+31
View File
@@ -153,3 +153,34 @@ func TestSearchJSONForEmail(t *testing.T) {
})
}
}
func TestSearchJSONForStringAttr(t *testing.T) {
t.Parallel()
tests := []struct {
Name string
SearchObject any
AttributePath string
ExpectedResult string
}{
{
Name: "Case insensitive contains using lower function from works correctly",
SearchObject: map[string]any{
"groups": []string{
"fOO",
},
},
AttributePath: "contains(groups[*].lower(@) ,lower('FOO')) && 'success' || 'failure'",
ExpectedResult: "success",
},
}
for _, test := range tests {
test := test
t.Run(test.Name, func(t *testing.T) {
t.Parallel()
actualResult, err := util.SearchJSONForStringAttr(test.AttributePath, test.SearchObject)
require.NoError(t, err)
require.Equal(t, test.ExpectedResult, actualResult)
})
}
}