1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/engine/jmespath/functionentry_test.go
Charles-Edouard Brétéché 417b2a9eba
chore: add a few unit tests for jp functions (#6219)
* chore: add a few unit tests for jp functions

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* refactor

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: shuting <shuting@nirmata.com>
2023-02-06 06:27:27 +00:00

64 lines
1.4 KiB
Go

package jmespath
import (
"testing"
gojmespath "github.com/jmespath/go-jmespath"
)
func TestFunctionEntry_String(t *testing.T) {
type fields struct {
FunctionEntry gojmespath.FunctionEntry
Note string
ReturnType []jpType
}
tests := []struct {
name string
fields fields
want string
}{{
fields: fields{
FunctionEntry: gojmespath.FunctionEntry{
Name: compare,
Arguments: []argSpec{
{Types: []jpType{jpString}},
{Types: []jpType{jpString}},
},
Handler: jpfCompare,
},
ReturnType: []jpType{jpNumber},
Note: "compares two strings lexicographically",
},
want: "compare(string, string) number (compares two strings lexicographically)",
}, {
fields: fields{
Note: "compares two strings lexicographically",
},
want: "",
}, {
fields: fields{
FunctionEntry: gojmespath.FunctionEntry{
Name: compare,
Arguments: []argSpec{
{Types: []jpType{jpString}},
{Types: []jpType{jpString}},
},
Handler: jpfCompare,
},
ReturnType: []jpType{jpNumber},
},
want: "compare(string, string) number",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := FunctionEntry{
FunctionEntry: tt.fields.FunctionEntry,
Note: tt.fields.Note,
ReturnType: tt.fields.ReturnType,
}
if got := f.String(); got != tt.want {
t.Errorf("FunctionEntry.String() = %v, want %v", got, tt.want)
}
})
}
}