-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem_builder_test.go
More file actions
35 lines (31 loc) · 916 Bytes
/
problem_builder_test.go
File metadata and controls
35 lines (31 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package httpsuite
import (
"net/http"
"testing"
)
func TestProblemBuilder(t *testing.T) {
t.Parallel()
problem := Problem(http.StatusBadRequest).
Type(GetProblemTypeURL("bad_request_error")).
Title("Validation Error").
Detail("invalid payload").
Instance("/users").
Extension("request_id", "req-123").
Extensions(map[string]any{"trace_id": "trace-456"}).
Build()
if problem.Status != http.StatusBadRequest {
t.Fatalf("expected status %d, got %d", http.StatusBadRequest, problem.Status)
}
if problem.Type != GetProblemTypeURL("bad_request_error") {
t.Fatalf("unexpected type %q", problem.Type)
}
if problem.Instance != "/users" {
t.Fatalf("unexpected instance %q", problem.Instance)
}
if problem.Extensions["request_id"] != "req-123" {
t.Fatalf("expected request_id extension")
}
if problem.Extensions["trace_id"] != "trace-456" {
t.Fatalf("expected trace_id extension")
}
}