layer1: centralize namespace watcher handlers
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
k8sCache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
@@ -337,6 +338,32 @@ func TestRecordNamespaceRemoval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleWatcherNamespaceAddUpdateDelete(t *testing.T) {
|
||||
manager := NewNamespaceManager()
|
||||
router := &testNamespaceSubscriber{name: "router"}
|
||||
manager.Subscribe(router)
|
||||
logger := zap.NewNop()
|
||||
namespace := &corev1.Namespace{}
|
||||
namespace.Name = "tenant-a"
|
||||
namespace.Labels = map[string]string{ManagedNamespaceLabelKey: ManagedNamespaceLabelValue}
|
||||
|
||||
HandleWatcherNamespaceAdd(context.Background(), logger, "router.NSWatcher", manager, namespace)
|
||||
if router.addCalls != 1 {
|
||||
t.Fatalf("expected add handler to dispatch add")
|
||||
}
|
||||
|
||||
HandleWatcherNamespaceUpdate(context.Background(), logger, "router.NSWatcher", manager, namespace, namespace)
|
||||
if router.resyncCalls != 1 {
|
||||
t.Fatalf("expected update handler to dispatch resync")
|
||||
}
|
||||
|
||||
HandleWatcherNamespaceDelete(logger, "router.NSWatcher", manager, k8sCache.DeletedFinalStateUnknown{Obj: namespace})
|
||||
record, ok := manager.Get("tenant-a")
|
||||
if !ok || record.Phase != NamespacePhaseRemoved {
|
||||
t.Fatalf("expected delete handler to mark namespace removed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceManagerDispatchAdd(t *testing.T) {
|
||||
manager := NewNamespaceManager()
|
||||
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-a", Source: NamespaceSourceWatcher})
|
||||
|
||||
Reference in New Issue
Block a user