forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresentation_error_test.go
42 lines (36 loc) · 1.04 KB
/
presentation_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 errcode
import (
"testing"
"github.com/pkg/errors"
)
func TestPresentationError(t *testing.T) {
t.Run("WithPresentationMessage", func(t *testing.T) {
t.Run("nil", func(t *testing.T) {
err := WithPresentationMessage(nil, "m")
if err != nil {
t.Errorf("got %v, want nil", err)
}
})
t.Run("root", func(t *testing.T) {
err := WithPresentationMessage(errors.New("x"), "m")
if got, want := PresentationMessage(err), "m"; got != want {
t.Errorf("got %q, want %q", got, want)
}
})
t.Run("wrapped", func(t *testing.T) {
err := errors.WithMessage(WithPresentationMessage(errors.New("x"), "m"), "y")
if got, want := PresentationMessage(err), "m"; got != want {
t.Errorf("got %q, want %q", got, want)
}
})
})
t.Run("NewPresentationError", func(t *testing.T) {
err := NewPresentationError("m")
if got, want := PresentationMessage(err), "m"; got != want {
t.Errorf("got %q, want %q", got, want)
}
if got, want := err.Error(), "m"; got != want {
t.Errorf("got %q, want %q", got, want)
}
})
}