TestCheckRole tests the CheckRole method
(t *testing.T)
| 29 | |
| 30 | // TestCheckRole tests the CheckRole method |
| 31 | func TestCheckRole(t *testing.T) { |
| 32 | tests := []struct { |
| 33 | name string |
| 34 | gotRole Role |
| 35 | wantRole Role |
| 36 | wantError bool |
| 37 | }{ |
| 38 | {"downloader", Downloader, Downloader, false}, |
| 39 | {"uploader", Uploader, Uploader, false}, |
| 40 | {"invalid", Downloader, "invalid", true}, |
| 41 | {"does not match", Uploader, Downloader, true}, |
| 42 | {"does not match", Downloader, Uploader, true}, |
| 43 | } |
| 44 | |
| 45 | for _, tc := range tests { |
| 46 | t.Run(tc.name, func(t *testing.T) { |
| 47 | assert := assert.New(t) |
| 48 | c := &Claims{ |
| 49 | Role: tc.gotRole, |
| 50 | } |
| 51 | |
| 52 | err := c.CheckRole(tc.wantRole) |
| 53 | if tc.wantError { |
| 54 | assert.Error(err) |
| 55 | } else { |
| 56 | assert.NoError(err) |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // TestValid tests the Valid method |
| 63 | func TestValid(t *testing.T) { |