-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
errors_test.go
89 lines (84 loc) · 1.82 KB
/
errors_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package opc
import (
"testing"
)
func TestError_Code(t *testing.T) {
tests := []struct {
name string
e *Error
want int
}{
{"empty", new(Error), 0},
{"base", newError(1, "base"), 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.e.Code(); got != tt.want {
t.Errorf("Error.Code() = %v, want %v", got, tt.want)
}
})
}
}
func TestError_PartName(t *testing.T) {
tests := []struct {
name string
e *Error
want string
}{
{"empty", new(Error), ""},
{"base", &Error{partName: "base"}, "base"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.e.PartName(); got != tt.want {
t.Errorf("Error.PartName() = %v, want %v", got, tt.want)
}
})
}
}
func TestError_Error(t *testing.T) {
tests := []struct {
name string
e *Error
want string
wantPanic bool
}{
{"base", &Error{101, "/doc.xml", ""}, "opc: /doc.xml: a part name shall not be empty", false},
{"panic", &Error{0, "/doc.xml", ""}, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if r := recover(); r != nil {
if !tt.wantPanic {
t.Errorf("Error.Error() want panic")
}
}
}()
if got := tt.e.Error(); got != tt.want {
t.Errorf("Error.Error() = %v, want %v", got, tt.want)
return
}
if tt.wantPanic {
t.Error("Error.Error() want error")
}
})
}
}
func TestError_RelationshipID(t *testing.T) {
tests := []struct {
name string
e *Error
want string
}{
{"empty", new(Error), ""},
{"base", newErrorRelationship(101, "/doc.xml", "21211"), "21211"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.e.RelationshipID(); got != tt.want {
t.Errorf("Error.RelationshipID() = %v, want %v", got, tt.want)
}
})
}
}