1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 07:26:55 +00:00
kyverno/pkg/utils/kube/tombstone_test.go
Charles-Edouard Brétéché 5313f0e46f
chore: add a couple unit tests (#5834)
* 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>
2023-01-03 09:56:57 +01:00

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)
}
}