layer1: add namespace manager bridge step 12
This commit is contained in:
@@ -35,6 +35,15 @@ func NewNamespaceManager() NamespaceManager {
|
||||
}
|
||||
}
|
||||
|
||||
func NewBootstrappedNamespaceManager(resolver *NamespaceResolver, source NamespaceSource, observedAt time.Time) NamespaceManager {
|
||||
manager := NewNamespaceManager()
|
||||
if resolver == nil {
|
||||
return manager
|
||||
}
|
||||
manager.Bootstrap(resolver.Snapshot(), source, observedAt)
|
||||
return manager
|
||||
}
|
||||
|
||||
func (m *inMemoryNamespaceManager) Subscribe(subscriber NamespaceSubscriber) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
@@ -157,4 +157,25 @@ func TestNamespaceManagerBootstrap(t *testing.T) {
|
||||
if record.Source != NamespaceSourceBackfill {
|
||||
t.Fatalf("expected bootstrap source backfill, got %s", record.Source)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBootstrappedNamespaceManager(t *testing.T) {
|
||||
resolver := &NamespaceResolver{
|
||||
FissionResourceNS: map[string]string{
|
||||
"tenant-b": "tenant-b",
|
||||
"tenant-a": "tenant-a",
|
||||
},
|
||||
}
|
||||
|
||||
manager := NewBootstrappedNamespaceManager(resolver, NamespaceSourceEnv, time.Now().UTC())
|
||||
if !reflect.DeepEqual([]string{"tenant-a", "tenant-b"}, manager.Snapshot()) {
|
||||
t.Fatalf("expected bootstrapped manager snapshot from resolver")
|
||||
}
|
||||
record, ok := manager.Get("tenant-a")
|
||||
if !ok {
|
||||
t.Fatalf("expected tenant-a in bootstrapped manager")
|
||||
}
|
||||
if record.Source != NamespaceSourceEnv {
|
||||
t.Fatalf("expected env source, got %s", record.Source)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user