-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
37 lines (33 loc) · 1.04 KB
/
error_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
package satomic_test
import (
"errors"
"testing"
)
import (
"github.com/dhui/satomic"
"github.com/dhui/satomic/satomictest"
)
func TestError(t *testing.T) {
testCases := []struct {
name string
err *satomic.Error
expectedStr string
}{
{name: "nil Error", err: nil, expectedStr: ""},
{name: "nil Err and Atomic", err: satomictest.NewError(nil, nil),
expectedStr: `Err: <nil> Atomic: <nil>`},
{name: "nil Err, non-nil Atomic", err: satomictest.NewError(nil, errors.New("atomic")),
expectedStr: `Err: <nil> Atomic: "atomic"`},
{name: "non-nil Err, nil Atomic", err: satomictest.NewError(errors.New("err"), nil),
expectedStr: `Err: "err" Atomic: <nil>`},
{name: "non-nil Err and Atomic", err: satomictest.NewError(errors.New("err"), errors.New("atomic")),
expectedStr: `Err: "err" Atomic: "atomic"`},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if str := tc.err.Error(); str != tc.expectedStr {
t.Error("Didn't get expected Error string:", str, "!=", tc.expectedStr)
}
})
}
}