-
Notifications
You must be signed in to change notification settings - Fork 2
/
constructor_test.go
62 lines (49 loc) · 1.39 KB
/
constructor_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
package serr
import (
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBasicConstruction(t *testing.T) {
errx := New("Test error message")
_, _, line, _ := runtime.Caller(0)
// expected
var (
exPath = fmt.Sprintf("/serr/constructor_test.go:%d", (line - 1))
exTitle = "Test error message"
exMsg = "Test error message"
)
if !assert.Contains(t, fmt.Sprintf("%s:%d", errx.File(), errx.Line()), exPath, "Error trace is not match") {
t.FailNow()
}
if !assert.Equal(t, errx.Title(), exTitle, "Error title is not match") {
t.FailNow()
}
if !assert.Equal(t, errx.Error(), exMsg, "Error message is not match") {
t.FailNow()
}
}
func TestBasicWithCommentConstruction(t *testing.T) {
errx := Newc("Test error message", "Test comments")
_, _, line, _ := runtime.Caller(0)
// expected
var (
exPath = fmt.Sprintf("/serr/constructor_test.go:%d", (line - 1))
exMsg = "Test error message"
exTitle = "Test comments"
exComment = "Test comments"
)
if !assert.Contains(t, fmt.Sprintf("%s:%d", errx.File(), errx.Line()), exPath, "Error trace is not match") {
t.FailNow()
}
if !assert.Equal(t, errx.Title(), exTitle, "Error title is not match") {
t.FailNow()
}
if !assert.Equal(t, errx.Comments(), exComment, "Error comment is not match") {
t.FailNow()
}
if !assert.Equal(t, errx.Error(), exMsg, "Error message is not match") {
t.FailNow()
}
}