-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelation_test.go
More file actions
71 lines (66 loc) · 2.63 KB
/
Copy pathrelation_test.go
File metadata and controls
71 lines (66 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package kernel
import (
"reflect"
"testing"
)
func TestRelationOwnsSelectionAndAuthority(t *testing.T) {
candidates := []RelationCandidate{
{ID: "low", Rank: 2, Priority: 1, Selectable: true},
{ID: "top", Rank: 1, Priority: 1, Selectable: true, RequiredAll: []Capability{"execute"}},
}
without := Relate(RelationInput{Candidates: candidates})
if without.Kind != Frontier || without.Transition != "top" {
t.Fatalf("without authority = %#v", without)
}
with := Relate(RelationInput{Candidates: candidates, Available: []Capability{"execute"}})
if with.Kind != Prescribed || with.Transition != "top" {
t.Fatalf("with authority = %#v", with)
}
}
func TestRelationTargetedAndUntargetedUseSameCandidates(t *testing.T) {
candidates := []RelationCandidate{{ID: "advance", Priority: 1, Selectable: true}}
untargeted := Relate(RelationInput{Candidates: candidates})
targeted := Relate(RelationInput{Requested: "advance", Candidates: candidates})
if untargeted.Kind != Prescribed || targeted.Kind != Prescribed || untargeted.Transition != targeted.Transition {
t.Fatalf("untargeted/targeted = %#v/%#v", untargeted, targeted)
}
refused := Relate(RelationInput{Requested: "other", Candidates: candidates})
if refused.Kind != Refused {
t.Fatalf("inadmissible target = %#v", refused)
}
}
func TestRelationReportsEqualPreferenceAndMarkedState(t *testing.T) {
tied, trace := RelateWithTrace(RelationInput{Candidates: []RelationCandidate{
{ID: "a", Priority: 1, Selectable: true},
{ID: "b", Priority: 1, Selectable: true},
}})
if tied.Kind != Frontier || len(tied.Candidates) != 2 {
t.Fatalf("tie = %#v", tied)
}
for _, candidate := range trace {
if candidate.Disposition != DispositionAmbiguous {
t.Fatalf("tie trace = %#v", trace)
}
}
marked := Relate(RelationInput{Marked: true})
if marked.Kind != Marked {
t.Fatalf("marked = %#v", marked)
}
}
func TestRelationTracePreservesAnyOfAndAllOfAuthority(t *testing.T) {
decision, trace := RelateWithTrace(RelationInput{
Candidates: []RelationCandidate{{
ID: "publish", Priority: 1, Selectable: true,
RequiredAny: []Capability{"authority.autonomy", "authority.human"},
RequiredAll: []Capability{"authority.external-provider"},
}},
Available: []Capability{"authority.autonomy"},
})
if decision.Kind != Frontier || len(trace) != 1 {
t.Fatalf("authority frontier = %#v / %#v", decision, trace)
}
authority := trace[0].Authority
if !authority.AnySatisfied || authority.AllSatisfied || authority.Satisfied || len(authority.MissingAny) != 0 || !reflect.DeepEqual(authority.MissingAll, []Capability{"authority.external-provider"}) {
t.Fatalf("authority clauses collapsed: %#v", authority)
}
}