-
Notifications
You must be signed in to change notification settings - Fork 2
/
json_error_test.go
65 lines (48 loc) · 1.38 KB
/
json_error_test.go
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
package jsonerror
import (
"reflect"
"testing"
)
func TestErrorJSON_AddError(t *testing.T) {
var err ErrorJSON
errorComposition := ErrorComp{
Detail: "this is a error message",
Code: "This is the code",
Status: 200,
}
err.AddError(errorComposition)
errorManually := ErrorJSON{Errors: []ErrorComp{{Detail: "this is a error message", Code: "This is the code", Status: 200}}}
reflect.DeepEqual(err, errorManually)
if !reflect.DeepEqual(err, errorManually) {
t.Fatalf("%#v != %#v", err, errorManually)
}
}
func TestErrorJSON_Error(t *testing.T) {
var err ErrorJSON
errorComposition := ErrorComp{
Detail: "this is a error message",
Code: "This is the code",
Source: Source{
Pointer: "/unit/tests",
},
Title: "Title Test",
Status: 200,
}
err.AddError(errorComposition)
errString := "{\"errors\":[{\"status\":200,\"code\":\"This is the code\",\"title\":\"Title Test\",\"detail\":\"this is a error message\",\"source\":{\"pointer\":\"/unit/tests\"}}]}"
if errString != err.Error() {
t.Fatal("The err string produced did not match up")
}
}
func TestErrorJSON_ErrorByte(t *testing.T) {
var err ErrorJSON
errorComposition := ErrorComp{
Detail: "this is a error message",
Code: "This is the code",
}
err.AddError(errorComposition)
typ := reflect.TypeOf(err.ErrorByte()).Kind()
if typ != reflect.Slice {
t.Fatal("Error was not returned as []byte")
}
}