forked from mfcochauxlaberge/jsonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_test.go
More file actions
71 lines (67 loc) · 1.46 KB
/
error_test.go
File metadata and controls
71 lines (67 loc) · 1.46 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
package jsonapi
import (
"net/http"
"testing"
"github.com/kkaribu/tchek"
)
func TestError(t *testing.T) {
tests := []struct {
name string
err Error
expectedString string
}{
{
name: "empty",
err: func() Error {
e := NewError()
return e
}(),
expectedString: "",
}, {
name: "title",
err: func() Error {
e := NewError()
e.Title = "An error"
return e
}(),
expectedString: "An error",
}, {
name: "detail",
err: func() Error {
e := NewError()
e.Detail = "An error occured."
return e
}(),
expectedString: "An error occured.",
}, {
name: "http status code",
err: func() Error {
e := NewError()
e.Status = http.StatusInternalServerError
return e
}(),
expectedString: "500 Internal Server Error",
}, {
name: "http status code and title",
err: func() Error {
e := NewError()
e.Status = http.StatusInternalServerError
e.Title = "Internal server error"
return e
}(),
expectedString: "500 Internal Server Error: Internal server error",
}, {
name: "http status code and detail",
err: func() Error {
e := NewError()
e.Status = http.StatusInternalServerError
e.Detail = "An internal server error occured."
return e
}(),
expectedString: "500 Internal Server Error: An internal server error occured.",
},
}
for _, test := range tests {
tchek.AreEqual(t, test.name, test.err.Error(), test.expectedString)
}
}