-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
73 lines (65 loc) · 1.65 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
package lightmigrate
import (
"errors"
"os"
"testing"
)
func TestErrDuplicateMigration_Error(t *testing.T) {
sampleFile := os.NewFile(0, "TheFileName.txt")
stat, _ := sampleFile.Stat()
e := ErrDuplicateMigration{
FileInfo: stat,
}
wantMsg := "duplicate migration file: TheFileName.txt"
if gotMsg := e.Error(); gotMsg != wantMsg {
t.Errorf("Error() = %v, want %v", gotMsg, wantMsg)
}
}
func TestDriverError_Error_NoMsg(t *testing.T) {
e := DriverError{
Line: 0,
Query: []byte("the db query"),
Msg: "",
OrigErr: errors.New("suberr"),
}
wantMsg := "suberr in line 0: the db query"
if gotMsg := e.Error(); gotMsg != wantMsg {
t.Errorf("Error() = %v, want %v", gotMsg, wantMsg)
}
}
func TestDriverError_Error_Msg(t *testing.T) {
e := DriverError{
Line: 0,
Query: []byte("the db query"),
Msg: "error message",
OrigErr: errors.New("suberr"),
}
wantMsg := "error message in line 0: the db query (details: suberr)"
if gotMsg := e.Error(); gotMsg != wantMsg {
t.Errorf("Error() = %v, want %v", gotMsg, wantMsg)
}
}
func TestDriverError_Unwrap_NoSubErr(t *testing.T) {
var wantSubErr error = nil
e := DriverError{
Line: 0,
Query: []byte("the db query"),
Msg: "error message",
OrigErr: wantSubErr,
}
if got := e.Unwrap(); got != wantSubErr {
t.Errorf("Unwrap() = %v, want %v", got, wantSubErr)
}
}
func TestDriverError_Unwrap_SubErr(t *testing.T) {
wantSubErr := errors.New("suberr")
e := DriverError{
Line: 0,
Query: []byte("the db query"),
Msg: "error message",
OrigErr: wantSubErr,
}
if got := e.Unwrap(); got != wantSubErr {
t.Errorf("Unwrap() = %v, want %v", got, wantSubErr)
}
}