layer1: add namespace tombstone helper step 34
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
k8sCache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
func TestNamespaceRecordClone(t *testing.T) {
|
||||
@@ -107,3 +108,40 @@ func TestNamespaceEventFromNamespace(t *testing.T) {
|
||||
t.Fatalf("expected event labels to stay detached from original namespace")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceFromObject(t *testing.T) {
|
||||
namespace := &corev1.Namespace{}
|
||||
namespace.Name = "tenant-a"
|
||||
|
||||
extracted, ok := NamespaceFromObject(namespace)
|
||||
if !ok || extracted.Name != "tenant-a" {
|
||||
t.Fatalf("expected namespace object to be extracted directly")
|
||||
}
|
||||
|
||||
extracted, ok = NamespaceFromObject(k8sCache.DeletedFinalStateUnknown{Obj: namespace})
|
||||
if !ok || extracted.Name != "tenant-a" {
|
||||
t.Fatalf("expected namespace tombstone to be extracted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceEventFromObject(t *testing.T) {
|
||||
namespace := &corev1.Namespace{}
|
||||
namespace.Name = "tenant-a"
|
||||
namespace.Labels = map[string]string{ManagedNamespaceLabelKey: ManagedNamespaceLabelValue}
|
||||
|
||||
event := NamespaceEventFromObject(NamespaceEventRemove, k8sCache.DeletedFinalStateUnknown{Obj: namespace}, NamespaceSourceWatcher, time.Now().UTC())
|
||||
if event.Type != NamespaceEventRemove {
|
||||
t.Fatalf("expected remove event type")
|
||||
}
|
||||
if event.Name != "tenant-a" {
|
||||
t.Fatalf("expected tenant-a event name")
|
||||
}
|
||||
if event.Labels[ManagedNamespaceLabelKey] != ManagedNamespaceLabelValue {
|
||||
t.Fatalf("expected labels copied from tombstone namespace")
|
||||
}
|
||||
|
||||
emptyEvent := NamespaceEventFromObject(NamespaceEventRemove, "not-a-namespace", NamespaceSourceWatcher, time.Now().UTC())
|
||||
if emptyEvent.Name != "" {
|
||||
t.Fatalf("expected empty name for unsupported object")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user