-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
42 lines (31 loc) · 909 Bytes
/
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
package bowtie
import (
"encoding/json"
"errors"
"testing"
)
func TestError(t *testing.T) {
m := "Hello there."
err := errors.New(m)
// Create a new error from a traditional Go error
e := NewErrorWithError(err).CaptureStackTrace()
if e.StatusCode() != 500 {
t.Errorf("Expected status code 500, got %d instead", e.StatusCode())
}
if e.Error() == m {
t.Errorf("Expected a generic error message, got %s instead", e.Error())
}
if e.String() == m {
t.Errorf("Expected a generic error message, got %s instead", e.Error())
}
data, err := json.Marshal(e)
if err != nil {
t.Fatalf("Unable to marshal Error instance to JSON: %s", err)
}
if string(data) != `{"message":"An server error has occurred.","statusCode":500}` {
t.Errorf("Unexpected JSON marshal received: %s", string(data))
}
if len(e.StackTrace()) != 3 {
t.Errorf("Unexpected stack trace: %#v", e.StackTrace())
}
}