| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "net/http/httptest" |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 9 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 10 | ) |
| 11 | |
| 12 | func TestRunnerBusinessRefusals(t *testing.T) { |
| 13 | for _, tc := range []struct { |
| 14 | err error |
| 15 | status int |
| 16 | key string |
| 17 | }{ |
| 18 | {team.ErrBudget, 409, "runner.budget"}, {team.ErrQuota, 409, "runner.quota"}, |
| 19 | {team.ErrEvidence, 422, "runner.evidence"}, {team.ErrState, 409, "form.conflict"}, |
| 20 | {team.ErrRevision, 409, "form.conflict"}, {team.ErrConflict, 409, "form.conflict"}, |
| 21 | {team.ErrContainment, 409, "runner.containment"}, {team.ErrReplayUnsafe, 409, "runner.replay"}, |
| 22 | {team.ErrUncertain, 409, "runner.uncertain"}, {team.ErrInvalid, 422, "form.invalid"}, |
| 23 | {ErrUnavailable, 503, "service.unavailable"}, |
| 24 | } { |
| 25 | t.Run(tc.key+tc.err.Error(), func(t *testing.T) { |
| 26 | w := httptest.NewRecorder() |
| 27 | runnerFailure(w, tc.err) |
| 28 | var body runnerproto.ErrorResponse |
| 29 | if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | if w.Code != tc.status || body.Error != tc.key { |
| 33 | t.Fatalf("refusal = %d %s; want %d %s", w.Code, body.Error, tc.status, tc.key) |
| 34 | } |
| 35 | }) |
| 36 | } |
| 37 | } |
| 38 | |