layer1: share namespace watcher event handlers
This commit is contained in:
@@ -406,6 +406,29 @@ func TestHandleWatcherNamespaceUpdateDispatchRemoval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewNamespaceWatcherEventHandlers(t *testing.T) {
|
||||
manager := NewNamespaceManager()
|
||||
router := &testNamespaceSubscriber{name: "router"}
|
||||
manager.Subscribe(router)
|
||||
logger := zap.NewNop()
|
||||
handlers := NewNamespaceWatcherEventHandlers(context.Background(), logger, "router.NSWatcher", manager, NamespaceRemovalStrategyTrackOnly)
|
||||
namespace := &corev1.Namespace{}
|
||||
namespace.Name = "tenant-a"
|
||||
namespace.Labels = map[string]string{ManagedNamespaceLabelKey: ManagedNamespaceLabelValue}
|
||||
|
||||
handlers.AddFunc(namespace)
|
||||
handlers.UpdateFunc(namespace, namespace)
|
||||
handlers.DeleteFunc(k8sCache.DeletedFinalStateUnknown{Obj: namespace})
|
||||
|
||||
record, ok := manager.Get("tenant-a")
|
||||
if !ok || record.Phase != NamespacePhaseRemoved {
|
||||
t.Fatalf("expected watcher event handlers to drive namespace lifecycle")
|
||||
}
|
||||
if router.addCalls != 1 || router.resyncCalls != 1 {
|
||||
t.Fatalf("expected add and resync calls through event handlers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceManagerDispatchAdd(t *testing.T) {
|
||||
manager := NewNamespaceManager()
|
||||
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-a", Source: NamespaceSourceWatcher})
|
||||
|
||||
Reference in New Issue
Block a user