(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestNewErrorEnvelopeShape(t *testing.T) { |
| 10 | e := NewError(http.StatusBadRequest, "domain_not_verified", "verify your domain first"). |
| 11 | WithDetails(map[string]string{"domain": "acme.com"}) |
| 12 | |
| 13 | if e.GetStatus() != http.StatusBadRequest { |
| 14 | t.Fatalf("status: got %d", e.GetStatus()) |
| 15 | } |
| 16 | if e.Code() != "domain_not_verified" { |
| 17 | t.Fatalf("code: got %q", e.Code()) |
| 18 | } |
| 19 | raw, _ := json.Marshal(e) |
| 20 | var decoded struct { |
| 21 | Error struct { |
| 22 | Code string `json:"code"` |
| 23 | Message string `json:"message"` |
| 24 | Details map[string]string `json:"details"` |
| 25 | } `json:"error"` |
| 26 | } |
| 27 | if err := json.Unmarshal(raw, &decoded); err != nil { |
| 28 | t.Fatalf("unmarshal: %v", err) |
| 29 | } |
| 30 | if decoded.Error.Code != "domain_not_verified" || |
| 31 | decoded.Error.Message != "verify your domain first" || |
| 32 | decoded.Error.Details["domain"] != "acme.com" { |
| 33 | t.Fatalf("unexpected envelope: %s", raw) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestDefaultCodeForStatus(t *testing.T) { |
| 38 | cases := map[int]string{ |
nothing calls this directly
no test coverage detected