-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder_test.go
39 lines (34 loc) · 935 Bytes
/
builder_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
package errors
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuiltinBuilder(t *testing.T) {
b := BuiltinBuilder.Errorf("a")
assert.Error(t, b)
assert.Equal(t, "a", b.Error())
}
func TestNewBuilder(t *testing.T) {
changingMap := map[string]string{"first": "orig"}
b := NewBuilder("t, %q", changingMap)
changingMap["second"] = "new"
err := b.Errorf("a")
assert.Equal(t, "a", err.Error())
assert.Regexp(
t,
`^[^ ]+/errors\.TestNewBuilder\(t, map\["first":"orig"\]\) builder_test\.go:[0-9]+ a$`,
StackString(err),
)
}
func TestNewLazyBuilder(t *testing.T) {
changingMap := map[string]string{"first": "orig"}
b := NewLazyBuilder("t, %q", changingMap)
changingMap["second"] = "new"
err := b.Errorf("a")
assert.Equal(t, "a", err.Error())
assert.Regexp(
t,
`^[^ ]+/errors\.TestNewLazyBuilder\(<lazy> t, map\[("[^"]+":"[^"]+" ?){2}\]\) builder_test\.go:[0-9]+ a$`,
StackString(err),
)
}