61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestDetectTransportOwnerLockConflicts(t *testing.T) {
|
|
current := []TransportPolicyIntent{
|
|
{SelectorType: "domain", SelectorValue: "example.com", ClientID: "c1"},
|
|
}
|
|
next := []TransportPolicyIntent{
|
|
{SelectorType: "domain", SelectorValue: "example.com", ClientID: "c2"},
|
|
}
|
|
clients := []TransportClient{
|
|
{ID: "c1", Status: TransportClientUp},
|
|
{ID: "c2", Status: TransportClientUp},
|
|
}
|
|
|
|
conflicts := detectTransportOwnerLockConflicts(current, next, clients)
|
|
if len(conflicts) != 1 {
|
|
t.Fatalf("expected 1 conflict, got %d (%#v)", len(conflicts), conflicts)
|
|
}
|
|
if conflicts[0].Type != "owner_lock" {
|
|
t.Fatalf("unexpected conflict type: %q", conflicts[0].Type)
|
|
}
|
|
if conflicts[0].Severity != "block" {
|
|
t.Fatalf("unexpected conflict severity: %q", conflicts[0].Severity)
|
|
}
|
|
}
|
|
|
|
func TestDetectTransportOwnerLockConflictsAllowsSwitchWhenPreviousOwnerDown(t *testing.T) {
|
|
current := []TransportPolicyIntent{
|
|
{SelectorType: "domain", SelectorValue: "example.com", ClientID: "c1"},
|
|
}
|
|
next := []TransportPolicyIntent{
|
|
{SelectorType: "domain", SelectorValue: "example.com", ClientID: "c2"},
|
|
}
|
|
clients := []TransportClient{
|
|
{ID: "c1", Status: TransportClientDown},
|
|
{ID: "c2", Status: TransportClientUp},
|
|
}
|
|
|
|
conflicts := detectTransportOwnerLockConflicts(current, next, clients)
|
|
if len(conflicts) != 0 {
|
|
t.Fatalf("expected no conflicts, got %#v", conflicts)
|
|
}
|
|
}
|
|
|
|
func TestIsTransportClientOwnerLockActive(t *testing.T) {
|
|
if !isTransportClientOwnerLockActive(TransportClientUp) {
|
|
t.Fatalf("up must be active")
|
|
}
|
|
if !isTransportClientOwnerLockActive(TransportClientStarting) {
|
|
t.Fatalf("starting must be active")
|
|
}
|
|
if !isTransportClientOwnerLockActive(TransportClientDegraded) {
|
|
t.Fatalf("degraded must be active")
|
|
}
|
|
if isTransportClientOwnerLockActive(TransportClientDown) {
|
|
t.Fatalf("down must be inactive")
|
|
}
|
|
}
|