Repository navigation
Expand file tree
/
Copy pathproblem_helpers_test.go
More file actions
74 lines (63 loc) · 2.28 KB
/
Copy pathproblem_helpers_test.go
File metadata and controls
74 lines (63 loc) · 2.28 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package httpsuite
import (
"net/http"
"testing"
)
func TestProblemBuilderHelpers(t *testing.T) {
t.Parallel()
badRequest := ProblemBadRequest("invalid page").Build()
if badRequest.Status != http.StatusBadRequest {
t.Fatalf("expected bad request status, got %d", badRequest.Status)
}
notFound := ProblemNotFound("user missing").Build()
if notFound.Status != http.StatusNotFound {
t.Fatalf("expected not found status, got %d", notFound.Status)
}
}
func TestStatusProblemHelpers(t *testing.T) {
t.Parallel()
tests := []struct {
name string
builder func(string) *ProblemBuilder
direct func(string) *ProblemDetails
status int
title string
errType string
}{
{"unauthorized", ProblemUnauthorized, NewUnauthorizedProblem, http.StatusUnauthorized, "Unauthorized", "unauthorized_error"},
{"forbidden", ProblemForbidden, NewForbiddenProblem, http.StatusForbidden, "Forbidden", "forbidden_error"},
{"conflict", ProblemConflict, NewConflictProblem, http.StatusConflict, "Conflict", "conflict_error"},
{"unprocessable", ProblemUnprocessable, NewUnprocessableProblem, http.StatusUnprocessableEntity, "Unprocessable Entity", "unprocessable_error"},
{"internal", ProblemInternal, NewInternalProblem, http.StatusInternalServerError, "Internal Server Error", "server_error"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
for _, got := range []*ProblemDetails{tt.builder("some detail").Build(), tt.direct("some detail")} {
if got.Status != tt.status {
t.Errorf("status = %d, want %d", got.Status, tt.status)
}
if got.Title != tt.title {
t.Errorf("title = %q, want %q", got.Title, tt.title)
}
if got.Detail != "some detail" {
t.Errorf("detail = %q", got.Detail)
}
if want := GetProblemTypeURL(tt.errType); got.Type != want || want == BlankURL {
t.Errorf("type = %q, want %q", got.Type, want)
}
}
})
}
}
func TestDirectProblemHelpers(t *testing.T) {
t.Parallel()
badRequest := NewBadRequestProblem("invalid payload")
if badRequest.Status != http.StatusBadRequest {
t.Fatalf("expected bad request status, got %d", badRequest.Status)
}
notFound := NewNotFoundProblem("user missing")
if notFound.Status != http.StatusNotFound {
t.Fatalf("expected not found status, got %d", notFound.Status)
}
}