package handoff import "testing" func TestPolicy(t *testing.T) { d := Authorize(PolicyContext{State: "READY_TO_HELP", Route: "test", HandoffEnabled: false, HandoffMode: HandoffModeARIRedirect, AllowInTestRouteOnly: true, HasTarget: true}) if !d.Allowed || !d.StubOnly { t.Fatalf("disabled must be stub only: %+v", d) } d = Authorize(PolicyContext{State: "READY_TO_HELP", Route: "test", HandoffEnabled: true, HandoffMode: HandoffModeARIRedirect, AllowInTestRouteOnly: true}) if !d.StubOnly || d.ReasonCode != "not_configured" { t.Fatalf("missing target should stub: %+v", d) } d = Authorize(PolicyContext{State: "READY_TO_HELP", Route: "production", HandoffEnabled: true, HandoffMode: HandoffModeARIRedirect, AllowInTestRouteOnly: true, HasTarget: true}) if !d.StubOnly { t.Fatalf("production should stub: %+v", d) } d = Authorize(PolicyContext{State: "ENDED", Route: "test", HandoffEnabled: true, HandoffMode: HandoffModeDisabledStub}) if d.Allowed { t.Fatalf("ended should deny: %+v", d) } }