70 lines
2.6 KiB
Go
70 lines
2.6 KiB
Go
package governance
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestPathAsksOnlyMembersWhoMayAnswer guards the escalation path: it never
|
|
// passes a request to an account that was left out as unable to answer, every
|
|
// step keeps its own deadline, and a target's known owner is asked before the
|
|
// default owner, which an unknown owner leaves first.
|
|
func TestPathAsksOnlyMembersWhoMayAnswer(t *testing.T) {
|
|
set := Settings{
|
|
ApprovalDeadline: time.Hour, DefaultOwner: "owner",
|
|
Escalation: []Step{
|
|
{Account: "peer", Deadline: 2 * time.Hour},
|
|
{Account: "lead", Deadline: 3 * time.Hour},
|
|
},
|
|
}
|
|
everyone := map[string]string{"owner": "Owner", "peer": "Peer", "lead": "Lead"}
|
|
leadOnly := map[string]string{"owner": "Owner", "lead": "Lead"}
|
|
tests := []struct {
|
|
name string
|
|
eligible map[string]string
|
|
// target is the account that answers for the action's target.
|
|
target string
|
|
want []string
|
|
wantDeadlines []time.Duration
|
|
}{
|
|
{
|
|
name: "an ordinary action goes through every step", eligible: everyone, want: []string{"Owner", "Peer", "Lead"},
|
|
wantDeadlines: []time.Duration{time.Hour, 2 * time.Hour, 3 * time.Hour},
|
|
},
|
|
{
|
|
name: "a step that may not answer is skipped", eligible: leadOnly,
|
|
want: []string{"Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 3 * time.Hour},
|
|
},
|
|
{
|
|
name: "the target's owner is asked first, then the default owner and the path", eligible: everyone, target: "peer",
|
|
want: []string{"Peer", "Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, time.Hour, 3 * time.Hour},
|
|
},
|
|
{
|
|
name: "a target owner who may not answer is not asked", eligible: leadOnly, target: "peer",
|
|
want: []string{"Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 3 * time.Hour},
|
|
},
|
|
{
|
|
name: "a target owner nobody knows leaves the default owner first", eligible: everyone, target: "stranger",
|
|
want: []string{"Owner", "Peer", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 2 * time.Hour, 3 * time.Hour},
|
|
},
|
|
{
|
|
name: "a default owner who may not answer leaves the first step open", eligible: map[string]string{"lead": "Lead"},
|
|
want: []string{"", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 3 * time.Hour},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var names []string
|
|
var deadlines []time.Duration
|
|
for _, st := range set.path(tt.eligible, tt.target) {
|
|
names = append(names, st.Name)
|
|
deadlines = append(deadlines, st.Deadline())
|
|
}
|
|
if !slices.Equal(names, tt.want) || !slices.Equal(deadlines, tt.wantDeadlines) {
|
|
t.Fatalf("path = %v %v, want %v %v", names, deadlines, tt.want, tt.wantDeadlines)
|
|
}
|
|
})
|
|
}
|
|
}
|