-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
50 lines (41 loc) · 996 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
43
44
45
46
47
48
49
50
package jh
import (
"net/http"
"testing"
"github.com/pkg/errors"
)
func TestNewHTTPError(t *testing.T) {
e := NewError("foo", http.StatusTeapot)
switch e.(type) {
case Error:
default:
t.Fatal("NewError did not return an Error")
}
ee := NewError(errors.Wrap(e, "more context!").Error(), http.StatusBadRequest)
switch ee.(type) {
case Error:
default:
t.Fatalf("NewError with a wrapped error did not return an Error")
}
}
func TestWrap(t *testing.T) {
{
var err error
if err := Wrap(err, "nothing"); err != nil {
t.Fatalf("Wrap did not leave nil error alone: %v", err)
}
}
{
err := Wrap(errors.New("foo"), "more")
if got, want := err.Status(), http.StatusInternalServerError; got != want {
t.Fatalf("wrong status; got: %v, want: %v", got, want)
}
}
{
s := http.StatusTeapot
err := Wrap(NewError("foo", s), "more")
if got, want := err.Status(), http.StatusTeapot; got != want {
t.Fatalf("wrong status; got: %v, want: %v", got, want)
}
}
}