mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-22 07:41:10 +00:00
chore: add some cel unit tests (#12453)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
082705a483
commit
06ac41e045
1 changed files with 37 additions and 0 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/google/cel-go/cel"
|
||||
"github.com/google/cel-go/common/types"
|
||||
"github.com/google/cel-go/common/types/ref"
|
||||
"github.com/kyverno/kyverno/pkg/cel/libs/resource"
|
||||
"github.com/kyverno/kyverno/pkg/globalcontext/store"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -92,3 +94,38 @@ func Test_impl_get_globalreference_string_string(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_impl_get_string_string(t *testing.T) {
|
||||
opts := Lib()
|
||||
base, err := cel.NewEnv(opts)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, base)
|
||||
tests := []struct {
|
||||
name string
|
||||
args []ref.Val
|
||||
want ref.Val
|
||||
}{{
|
||||
name: "not enough args",
|
||||
args: nil,
|
||||
want: types.NewErr("expected 3 arguments, got %d", 0),
|
||||
}, {
|
||||
name: "bad arg 1",
|
||||
args: []ref.Val{types.String("foo"), types.String("foo"), types.String("foo")},
|
||||
want: types.NewErr("unsupported native conversion from string to 'globalcontext.Context'"),
|
||||
}, {
|
||||
name: "bad arg 2",
|
||||
args: []ref.Val{base.CELTypeAdapter().NativeToValue(Context{}), types.Bool(false), types.String("foo")},
|
||||
want: types.NewErr("type conversion error from bool to 'string'"),
|
||||
}, {
|
||||
name: "bad arg 3",
|
||||
args: []ref.Val{base.CELTypeAdapter().NativeToValue(Context{}), types.String("foo"), types.Bool(false)},
|
||||
want: types.NewErr("type conversion error from bool to 'string'"),
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := &impl{}
|
||||
got := c.get_string_string(tt.args...)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue