mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
[Bug] Enabling many-to-one comparisons for AnyNotIn
operator (#9462)
* added cases for int, float Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> * added bool as well Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> * added tests Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> * some more tests Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> * go fmt Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> * fixed the failing test cases Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> --------- Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com> Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
022fc4f357
commit
dbc12ac2be
2 changed files with 96 additions and 1 deletions
|
@ -134,6 +134,14 @@ func anySetExistsInArray(key []string, value interface{}, log logr.Logger, anyNo
|
||||||
}
|
}
|
||||||
return false, isAnyIn(key, valueSlice)
|
return false, isAnyIn(key, valueSlice)
|
||||||
|
|
||||||
|
case int, int32, int64, float32, float64, bool:
|
||||||
|
var valueSlice []string
|
||||||
|
valueSlice = append(valueSlice, fmt.Sprint(value))
|
||||||
|
if anyNotIn {
|
||||||
|
return false, isAnyNotIn(key, valueSlice)
|
||||||
|
}
|
||||||
|
return false, isAnyIn(key, valueSlice)
|
||||||
|
|
||||||
case string:
|
case string:
|
||||||
if len(key) == 1 && key[0] == valuesAvailable {
|
if len(key) == 1 && key[0] == valuesAvailable {
|
||||||
if anyNotIn {
|
if anyNotIn {
|
||||||
|
|
|
@ -46,7 +46,6 @@ func TestAnyNotInHandler_Evaluate(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "key is int and in value",
|
name: "key is int and in value",
|
||||||
args: args{
|
args: args{
|
||||||
|
@ -55,6 +54,14 @@ func TestAnyNotInHandler_Evaluate(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "key is int and in value",
|
||||||
|
args: args{
|
||||||
|
key: 1,
|
||||||
|
value: []interface{}{1, 2, 3},
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "key is int and not in value",
|
name: "key is int and not in value",
|
||||||
args: args{
|
args: args{
|
||||||
|
@ -63,6 +70,38 @@ func TestAnyNotInHandler_Evaluate(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "key is float and in value",
|
||||||
|
args: args{
|
||||||
|
key: 3.14,
|
||||||
|
value: "3.14",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is float and in value",
|
||||||
|
args: args{
|
||||||
|
key: 2.2,
|
||||||
|
value: []interface{}{1.1, 2.2, 3.3},
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is float and not in value",
|
||||||
|
args: args{
|
||||||
|
key: 3.14,
|
||||||
|
value: "default",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is boolean and in value",
|
||||||
|
args: args{
|
||||||
|
key: true,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "key is array and in value",
|
name: "key is array and in value",
|
||||||
args: args{
|
args: args{
|
||||||
|
@ -87,6 +126,54 @@ func TestAnyNotInHandler_Evaluate(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "key is array of int and partially in value",
|
||||||
|
args: args{
|
||||||
|
key: []interface{}{1, 2, 3},
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is array of int and not in value",
|
||||||
|
args: args{
|
||||||
|
key: []interface{}{1, 2, 3},
|
||||||
|
value: 4,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is array of float and partially in value",
|
||||||
|
args: args{
|
||||||
|
key: []interface{}{1.1, 2.2, 3.3},
|
||||||
|
value: 1.1,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is array of float and not in value",
|
||||||
|
args: args{
|
||||||
|
key: []interface{}{1.1, 2.2, 3.3},
|
||||||
|
value: 4.4,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is array of bool and partially in value",
|
||||||
|
args: args{
|
||||||
|
key: []interface{}{true, false},
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key is an array of bool and not in value",
|
||||||
|
args: args{
|
||||||
|
key: []interface{}{true},
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "key and value are array and not in value",
|
name: "key and value are array and not in value",
|
||||||
args: args{
|
args: args{
|
||||||
|
|
Loading…
Reference in a new issue