Files
fission-src/pkg/utils/namespace_manager_model_test.go
T

67 lines
1.7 KiB
Go

package utils
import (
"testing"
"time"
)
func TestNamespaceRecordClone(t *testing.T) {
now := time.Now().UTC()
record := NamespaceRecord{
Name: "tenant-a",
Source: NamespaceSourceWatcher,
Phase: NamespacePhaseRegistering,
Generation: 7,
UpdatedAt: now,
Labels: map[string]string{
"fission.io/managed": "true",
},
RegisteredParts: map[string]NamespacePartState{
"router": {
State: "active",
UpdatedAt: now,
},
},
}
clone := record.Clone()
clone.Labels["fission.io/managed"] = "false"
clone.RegisteredParts["router"] = NamespacePartState{State: "failed", LastError: "boom"}
if record.Labels["fission.io/managed"] != "true" {
t.Fatalf("expected labels to be deep copied")
}
if record.RegisteredParts["router"].State != "active" {
t.Fatalf("expected registered parts to be deep copied")
}
}
func TestNamespaceRecordIsActive(t *testing.T) {
record := NamespaceRecord{Phase: NamespacePhaseActive}
if !record.IsActive() {
t.Fatalf("expected active phase to be reported as active")
}
record.Phase = NamespacePhaseRegistering
if record.IsActive() {
t.Fatalf("expected non-active phase to be reported as inactive")
}
}
func TestNamespaceRecordIsTerminal(t *testing.T) {
for _, test := range []struct {
phase NamespacePhase
expected bool
}{
{phase: NamespacePhaseRemoved, expected: true},
{phase: NamespacePhaseFailed, expected: true},
{phase: NamespacePhaseActive, expected: false},
{phase: NamespacePhaseRegistering, expected: false},
} {
record := NamespaceRecord{Phase: test.phase}
if record.IsTerminal() != test.expected {
t.Fatalf("expected terminal=%v for phase %s", test.expected, test.phase)
}
}
}