layer1: add namespace snapshot api step 1
This commit is contained in:
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -177,6 +178,44 @@ func TestNamespaceResolver(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Snapshot returns stable copy", func(t *testing.T) {
|
||||
nsr := &NamespaceResolver{
|
||||
FissionResourceNS: map[string]string{
|
||||
"ns-b": "ns-b",
|
||||
"ns-a": "ns-a",
|
||||
},
|
||||
}
|
||||
|
||||
snapshot := nsr.Snapshot()
|
||||
expected := []string{"ns-a", "ns-b"}
|
||||
if !reflect.DeepEqual(expected, snapshot) {
|
||||
t.Fatalf("expected snapshot %v, got %v", expected, snapshot)
|
||||
}
|
||||
|
||||
snapshot[0] = "mutated"
|
||||
if nsr.FissionResourceNS["ns-a"] != "ns-a" {
|
||||
t.Fatalf("snapshot mutated internal namespace map")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("SnapshotWithOptions includes expanded namespaces once", func(t *testing.T) {
|
||||
nsr := &NamespaceResolver{
|
||||
FunctionNamespace: "fn-ns",
|
||||
BuilderNamespace: "builder-ns",
|
||||
DefaultNamespace: "default",
|
||||
FissionResourceNS: map[string]string{
|
||||
"default": "default",
|
||||
"user-ns": "user-ns",
|
||||
},
|
||||
}
|
||||
|
||||
snapshot := nsr.SnapshotWithOptions(WithBuilderNs(), WithFunctionNs(), WithDefaultNs())
|
||||
expected := []string{"builder-ns", "default", "fn-ns", "user-ns"}
|
||||
if !reflect.DeepEqual(expected, snapshot) {
|
||||
t.Fatalf("expected snapshot with options %v, got %v", expected, snapshot)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("getNamespace", func(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user