Debian Codegraph @

api/v1/lib/scheduler/calls/calls_test.go

raw symbols SCIP
1 package calls_test
2
3 import (
4 "fmt"
5 "reflect"
6 "testing"
7
8 "github.com/mesos/mesos-go/api/v1/lib/scheduler"
9 "github.com/mesos/mesos-go/api/v1/lib/scheduler/calls"
10 )
11
12 func TestRole(t *testing.T) {
13 var (
14 rolesNone []string
15 roleX = []string{"x"}
16 )
17 for ti, tc := range []struct {
18 call *scheduler.Call
19 roles []string
20 }{
21 {calls.Revive(), rolesNone},
22 {calls.Suppress(), rolesNone},
23
24 {calls.ReviveWith(nil), rolesNone},
25 {calls.SuppressWith(nil), rolesNone},
26
27 {calls.ReviveWith(roleX), roleX},
28 {calls.SuppressWith(roleX), roleX},
29 } {
30 roles, hasRole := func() ([]string, bool) {
31 switch tc.call.Type {
32 case scheduler.Call_SUPPRESS:
33 return tc.call.GetSuppress().GetRoles(), len(tc.call.GetSuppress().GetRoles()) > 0
34 case scheduler.Call_REVIVE:
35 return tc.call.GetRevive().GetRoles(), len(tc.call.GetRevive().GetRoles()) > 0
36 default:
37 panic(fmt.Sprintf("test case %d failed: unsupported call type: %v", ti, tc.call.Type))
38 }
39 }()
40 if hasRole != (len(tc.roles) > 0) {
41 if hasRole {
42 t.Errorf("test case %d failed: expected no role instead of %q", ti, roles)
43 } else {
44 t.Errorf("test case %d failed: expected role %q instead of no role", ti, tc.roles)
45 }
46 }
47 if hasRole && !reflect.DeepEqual(tc.roles, roles) {
48 t.Errorf("test case %d failed: expected role %q instead of %q", ti, tc.roles, roles)
49 }
50 }
51 }