1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00
kyverno/cmd/cli/kubectl-kyverno/resource/tidy_test.go
Charles-Edouard Brétéché 5360248135
refactor: combine unstructured and resource packages (#8276)
* refactor: introduce userinfo package in the cli

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

* fix

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

* refactor: introduce api package in cli

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

* fix

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

* refactor: combine unstructured and resource packages

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

* fix

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

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-05 21:09:31 +00:00

95 lines
1.7 KiB
Go

package resource
import (
"reflect"
"testing"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func Test_tidy(t *testing.T) {
tests := []struct {
name string
obj interface{}
want interface{}
}{{
obj: "string",
want: "string",
}, {
obj: map[string]interface{}{},
want: nil,
}, {
obj: nil,
want: nil,
}, {
obj: []interface{}{},
want: nil,
}, {
obj: map[string]interface{}{
"map": nil,
},
want: nil,
}, {
obj: map[string]interface{}{
"map": map[string]interface{}{},
},
want: nil,
}, {
obj: map[string]interface{}{
"map": map[string]interface{}{
"foo": "bar",
},
},
want: map[string]interface{}{
"map": map[string]interface{}{
"foo": "bar",
},
},
}, {
obj: []interface{}{[]interface{}{}},
want: nil,
}, {
obj: []interface{}{1},
want: []interface{}{1},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tidy(tt.obj); !reflect.DeepEqual(got, tt.want) {
t.Errorf("TidyObject() = %v, want %v", got, tt.want)
}
})
}
}
func TestTidy(t *testing.T) {
tests := []struct {
name string
obj unstructured.Unstructured
want unstructured.Unstructured
}{{
obj: unstructured.Unstructured{},
want: unstructured.Unstructured{},
}, {
obj: unstructured.Unstructured{
Object: map[string]interface{}{
"map": map[string]interface{}{
"foo": "bar",
},
},
},
want: unstructured.Unstructured{
Object: map[string]interface{}{
"map": map[string]interface{}{
"foo": "bar",
},
},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Tidy(tt.obj); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Tidy() = %v, want %v", got, tt.want)
}
})
}
}