mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 15:37:19 +00:00
* chore: add LabelSelectorContainsWildcard unit tests Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * tombstone tests Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * ConvertToUnstructured tests Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package kube
|
|
|
|
import (
|
|
"testing"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/tools/cache"
|
|
)
|
|
|
|
func TestGetObjectWithTombstonePositive(t *testing.T) {
|
|
// Test that the GetObjectWithTombstone function returns the object when given a DeletedFinalStateUnknown object
|
|
obj := &corev1.Pod{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-pod",
|
|
},
|
|
}
|
|
tombstone := cache.DeletedFinalStateUnknown{
|
|
Obj: obj,
|
|
}
|
|
result := GetObjectWithTombstone(tombstone)
|
|
if result != obj {
|
|
t.Errorf("Expected GetObjectWithTombstone to return the original object, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestGetObjectWithTombstoneNegative(t *testing.T) {
|
|
// Test that the GetObjectWithTombstone function returns the original object when not given a DeletedFinalStateUnknown object
|
|
obj := &corev1.Pod{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-pod",
|
|
},
|
|
}
|
|
result := GetObjectWithTombstone(obj)
|
|
if result != obj {
|
|
t.Errorf("Expected GetObjectWithTombstone to return the original object, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestGetObjectWithTombstoneNil(t *testing.T) {
|
|
// Test that the GetObjectWithTombstone function returns nil when given a nil object
|
|
result := GetObjectWithTombstone(nil)
|
|
if result != nil {
|
|
t.Errorf("Expected GetObjectWithTombstone to return nil, got %v", result)
|
|
}
|
|
}
|