-
Notifications
You must be signed in to change notification settings - Fork 6
/
error_test.go
61 lines (51 loc) · 1.68 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
57
58
59
60
61
package restit_test
import (
"testing"
restit "github.com/go-restit/restit/v2"
)
func TestContextError_EmptyString(t *testing.T) {
err := restit.NewContextError("")
var err2 error = err
if want, have := "", err2.Error(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
}
func TestContextError_NoMessage(t *testing.T) {
err := restit.NewContextError("")
err.Delete("message")
var err2 error = err
if want, have := "error", err2.Error(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
}
func TestContextError_AppendPrepend(t *testing.T) {
err := restit.NewContextError("dummy %s", "error")
var err2 error = err
if want, have := "dummy error", err2.Error(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
err.Append("foo", "bar")
if want, have := `message="dummy error" foo="bar"`, err.Log(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
err.Prepend("hello", "world")
if want, have := `hello="world" message="dummy error" foo="bar"`, err.Log(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
err.Prepend("foo", "bar")
if want, have := `foo="bar" hello="world" message="dummy error"`, err.Log(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
}
func TestExpandError(t *testing.T) {
err := restit.NewContextError("dummy %s", "error")
err.Append("foo", "bar")
if want, have := `message="dummy error" foo="bar"`, err.Log(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
var err2 error = err
err3 := restit.ExpandError(err2)
if want, have := `message="dummy error" foo="bar"`, err3.Log(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
}