-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfactory_test.go
67 lines (60 loc) · 1.75 KB
/
factory_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
package gerror_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/drshriveer/gtools/gerror"
)
func TestCloneBase(t *testing.T) {
t.Parallel()
ErrNoMessage := gerror.FactoryOf(&gerror.GError{
Name: "ErrBase",
Message: "",
Source: "",
})
tests := []struct {
description string
input gerror.Error
expectedName string
expectedMessage string
expectedSource string
expectedDetailTag string
}{
{
description: "add message does not include extra white space",
input: ErrNoMessage.Msg("hi! blah"),
expectedName: "ErrBase",
expectedSource: "gerror_test:TestCloneBase",
expectedMessage: "hi! blah",
},
{
description: "add message is trimmed",
input: ErrNoMessage.Msg(" hi! blah "),
expectedName: "ErrBase",
expectedSource: "gerror_test:TestCloneBase",
expectedMessage: "hi! blah",
},
{
description: "add message is trimmed + chaining",
input: ErrNoMessage.Msg(" hi! blah ").(*gerror.GError).Msg(" \t bye! "),
expectedName: "ErrBase",
expectedSource: "gerror_test:TestCloneBase",
expectedMessage: "hi! blah bye!",
},
{
description: "lots of whitespace is trimmed",
input: ErrNoMessage.Msg(" hi! blah \n"),
expectedName: "ErrBase",
expectedSource: "gerror_test:TestCloneBase",
expectedMessage: "hi! blah",
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
t.Parallel()
assert.Equal(t, test.expectedName, test.input.ErrName())
assert.Equal(t, test.expectedMessage, test.input.ErrMessage())
assert.Equal(t, test.expectedSource, test.input.ErrSource())
assert.Equal(t, test.expectedDetailTag, test.input.ErrDetailTag())
})
}
}