github.com/grailbio/base@v0.0.11/cmd/ticket-server/service_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 6 "github.com/grailbio/base/security/ticket" 7 ) 8 9 func TestCheckControls(t *testing.T) { 10 cases := []struct { 11 s service 12 args map[string]string 13 wantOk bool 14 wantErrMsg string 15 }{ 16 { 17 service{}, 18 map[string]string{}, 19 true, 20 "", 21 }, 22 { 23 service{ 24 controls: map[ticket.Control]bool{ 25 ticket.ControlRationale: true, 26 }, 27 }, 28 map[string]string{ 29 "Rationale": "rationale", 30 }, 31 true, 32 "", 33 }, 34 { 35 service{ 36 controls: map[ticket.Control]bool{ 37 ticket.ControlRationale: true, 38 }, 39 }, 40 map[string]string{}, 41 false, 42 "missing required argument: Rationale", 43 }, 44 } 45 for _, c := range cases { 46 ok, err := c.s.checkControls(nil, nil, c.args) 47 if ok != c.wantOk { 48 t.Errorf("unexpected ok value: got: %t, want: %t", ok, c.wantOk) 49 } 50 if c.wantErrMsg != "" && err.Error() != c.wantErrMsg { 51 t.Errorf("unexpected err value: got: %s, want: %s", err.Error(), c.wantErrMsg) 52 } 53 } 54 55 }