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/variables_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

91 lines
1.8 KiB
Go

package variables
import (
"reflect"
"testing"
valuesapi "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/values"
)
func TestVariables_HasVariables(t *testing.T) {
tests := []struct {
name string
values *valuesapi.Values
variables map[string]string
want bool
}{{
name: "nil",
values: nil,
variables: nil,
want: false,
}, {
name: "empty",
values: nil,
variables: map[string]string{},
want: false,
}, {
name: "not empty",
values: nil,
variables: map[string]string{
"foo": "bar",
},
want: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := Variables{
values: tt.values,
variables: tt.variables,
}
if got := v.HasVariables(); got != tt.want {
t.Errorf("Variables.HasVariables() = %v, want %v", got, tt.want)
}
})
}
}
func TestVariables_Subresources(t *testing.T) {
tests := []struct {
name string
values *valuesapi.Values
variables map[string]string
want []valuesapi.Subresource
}{{
name: "nil values",
values: nil,
variables: nil,
want: nil,
}, {
name: "nil subresources",
values: &valuesapi.Values{
Subresources: nil,
},
variables: nil,
want: nil,
}, {
name: "empty subresources",
values: &valuesapi.Values{
Subresources: []valuesapi.Subresource{},
},
variables: nil,
want: nil,
}, {
name: "subresources",
values: &valuesapi.Values{
Subresources: []valuesapi.Subresource{{}},
},
variables: nil,
want: []valuesapi.Subresource{{}},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := Variables{
values: tt.values,
variables: tt.variables,
}
if got := v.Subresources(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Variables.Subresources() = %v, want %v", got, tt.want)
}
})
}
}