1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/cmd/cli/kubectl-kyverno/variables/utils_test.go
Charles-Edouard Brétéché 2d8c74eb12
chore: improve unit tests in cli (#8296)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-06 17:01:23 +00:00

79 lines
1.4 KiB
Go

package variables
import (
"testing"
)
func TestNeedsVariable(t *testing.T) {
tests := []struct {
name string
want bool
}{{
name: "",
want: false,
}, {
name: "request.object.spec",
want: false,
}, {
name: "request.operation",
want: false,
}, {
name: "element.spec.container",
want: false,
}, {
name: "elementIndex",
want: false,
}, {
name: "foo",
want: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NeedsVariable(tt.name); got != tt.want {
t.Errorf("NeedsVariable() = %v, want %v", got, tt.want)
}
})
}
}
func TestNeedsVariables(t *testing.T) {
tests := []struct {
name string
variables []string
want bool
}{{
name: "nil",
variables: nil,
want: false,
}, {
name: "empty",
variables: []string{},
want: false,
}, {
name: "false",
variables: []string{
"request.object.spec",
"request.operation",
"element.spec.container",
"elementIndex",
},
want: false,
}, {
name: "true",
variables: []string{
"request.object.spec",
"request.operation",
"element.spec.container",
"elementIndex",
"foo",
},
want: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NeedsVariables(tt.variables...); got != tt.want {
t.Errorf("NeedsVariables() = %v, want %v", got, tt.want)
}
})
}
}