forked from makiuchi-d/gozxing
-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer_exception_test.go
55 lines (45 loc) · 1.2 KB
/
writer_exception_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
package gozxing
import (
"fmt"
"testing"
errors "golang.org/x/xerrors"
)
func testWriterErrorType(t testing.TB, e error) {
t.Helper()
var we WriterException
if !errors.As(e, &we) {
t.Fatalf("Type must be WriterException")
}
var re ReaderException
if errors.As(e, &re) {
t.Fatalf("Type must not be ReaderException")
}
if _, ok := e.(WriterException); !ok {
t.Fatalf("Type must be WriterException")
}
if _, ok := e.(ReaderException); ok {
t.Fatalf("Type must not be ReaderException")
}
we.writerException()
}
func TestNewWriterException(t *testing.T) {
var e error = NewWriterException("test message")
testWriterErrorType(t, e)
}
func TestWrapWriterException(t *testing.T) {
base := errors.New("test error")
var e error = WrapWriterException(base)
testWriterErrorType(t, e)
if !errors.Is(e, base) {
t.Fatalf("err(%v) is not base(%v)", e, base)
}
wants := "WriterException: test error"
if msg := fmt.Sprintf("%v", e); msg != wants {
t.Fatalf("e.Error() = \"%s\", wants \"%s\"", msg, wants)
}
e = WrapWriterException(e)
wants = "WriterException: WriterException: test error"
if msg := fmt.Sprintf("%v", e); msg != wants {
t.Fatalf("e.Error() = \"%s\", wants \"%s\"", msg, wants)
}
}