-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy patherror_test.go
56 lines (43 loc) · 1.04 KB
/
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
package getstream_test
import (
"encoding/json"
"testing"
"time"
getstream "github.com/GetStream/stream-go"
)
func TestError(t *testing.T) {
errorResponse := "{\"code\": 5, \"detail\": \"some detail\", \"duration\": \"36ms\", \"exception\": \"an exception\", \"status_code\": 400}"
var getStreamError getstream.Error
err := json.Unmarshal([]byte(errorResponse), &getStreamError)
if err != nil {
t.Fatal(err)
}
testError := getstream.Error{
Code: 5,
Detail: "some detail",
RawDuration: "36ms",
Exception: "an exception",
StatusCode: 400,
}
if getStreamError != testError {
t.Error(err)
}
if getStreamError.Duration() != time.Millisecond*36 {
t.Error(err)
}
if getStreamError.Error() != "an exception (36ms): some detail" {
t.Error(err)
}
}
func TestErrorBadDuration(t *testing.T) {
testError := getstream.Error{
Code: 5,
Detail: "some detail",
RawDuration: "36blah",
Exception: "an exception",
StatusCode: 400,
}
if testError.Duration() != time.Duration(0) {
t.Fatal()
}
}