-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresponse_helpers_test.go
More file actions
46 lines (40 loc) · 1.17 KB
/
response_helpers_test.go
File metadata and controls
46 lines (40 loc) · 1.17 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
package httpsuite
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestResponseHelpers(t *testing.T) {
t.Parallel()
t.Run("ok helper", func(t *testing.T) {
w := httptest.NewRecorder()
OK(w, testResponse{Key: "value"})
if w.Code != http.StatusOK {
t.Fatalf("expected status %d, got %d", http.StatusOK, w.Code)
}
})
t.Run("ok with meta helper", func(t *testing.T) {
w := httptest.NewRecorder()
OKWithMeta(w, []string{"a"}, NewPageMeta(1, 10, 15))
if w.Code != http.StatusOK {
t.Fatalf("expected status %d, got %d", http.StatusOK, w.Code)
}
})
t.Run("created helper", func(t *testing.T) {
w := httptest.NewRecorder()
Created(w, testResponse{Key: "value"}, "/users/1")
if w.Code != http.StatusCreated {
t.Fatalf("expected status %d, got %d", http.StatusCreated, w.Code)
}
if got := w.Header().Get("Location"); got != "/users/1" {
t.Fatalf("expected location header, got %q", got)
}
})
t.Run("problem helper", func(t *testing.T) {
w := httptest.NewRecorder()
ProblemResponse(w, NewNotFoundProblem("user missing"))
if w.Code != http.StatusNotFound {
t.Fatalf("expected status %d, got %d", http.StatusNotFound, w.Code)
}
})
}