34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestAttachTransportOwnershipLockState(t *testing.T) {
|
|
items := []TransportOwnershipRecord{
|
|
{Key: "domain:a.example", ClientID: "c1"},
|
|
{Key: "domain:b.example", ClientID: "c2"},
|
|
{Key: "domain:c.example", ClientID: "c3"},
|
|
}
|
|
clients := []TransportClient{
|
|
{ID: "c1", Status: TransportClientUp},
|
|
{ID: "c2", Status: TransportClientDown},
|
|
{ID: "c3", Status: TransportClientDegraded},
|
|
}
|
|
|
|
annotated, lockCount := attachTransportOwnershipLockState(items, clients)
|
|
if len(annotated) != len(items) {
|
|
t.Fatalf("unexpected items len: %d", len(annotated))
|
|
}
|
|
if lockCount != 2 {
|
|
t.Fatalf("expected lockCount=2, got %d", lockCount)
|
|
}
|
|
if !annotated[0].LockActive || annotated[0].OwnerStatus != "up" {
|
|
t.Fatalf("unexpected c1 state: %#v", annotated[0])
|
|
}
|
|
if annotated[1].LockActive || annotated[1].OwnerStatus != "down" {
|
|
t.Fatalf("unexpected c2 state: %#v", annotated[1])
|
|
}
|
|
if !annotated[2].LockActive || annotated[2].OwnerStatus != "degraded" {
|
|
t.Fatalf("unexpected c3 state: %#v", annotated[2])
|
|
}
|
|
}
|