MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestNewErrorEnvelopeShape

Function TestNewErrorEnvelopeShape

internal/httpapi/errors_test.go:9–35  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func 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
37func TestDefaultCodeForStatus(t *testing.T) {
38 cases := map[int]string{

Callers

nothing calls this directly

Calls 4

NewErrorFunction · 0.85
WithDetailsMethod · 0.80
GetStatusMethod · 0.80
CodeMethod · 0.80

Tested by

no test coverage detected