Repository navigation
Expand file tree
/
Copy patherrors_test.go
More file actions
100 lines (67 loc) · 1.97 KB
/
Copy patherrors_test.go
File metadata and controls
100 lines (67 loc) · 1.97 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package option //nolint:testpackage
// this is unit test, that checks internal logic of error constructing.
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var (
errTest = errors.New("some error")
)
func TestEncodeError_Error(t *testing.T) {
t.Parallel()
t.Run("newEncodeError with error", func(t *testing.T) {
t.Parallel()
a := newEncodeError("Byte", errTest)
require.Error(t, a)
assert.Equal(t, "failed to encode Byte: some error", a.Error())
})
t.Run("newEncodeError without error", func(t *testing.T) {
t.Parallel()
a := newEncodeError("Byte", nil)
require.NoError(t, a)
})
t.Run("newEncoderGenericError", func(t *testing.T) {
t.Parallel()
a := newEncodeGenericError[int](errTest)
require.Error(t, a)
assert.Equal(t, "failed to encode Generic[int]: some error", a.Error())
})
t.Run("newEncodeGenericError without error", func(t *testing.T) {
t.Parallel()
a := newEncodeGenericError[int](nil)
require.NoError(t, a)
})
}
func TestDecodeError_Error(t *testing.T) {
t.Parallel()
t.Run("newDecodeError with error", func(t *testing.T) {
t.Parallel()
a := newDecodeError("Byte", errTest)
require.Error(t, a)
assert.Equal(t, "failed to decode Byte: some error", a.Error())
})
t.Run("newDecodeError without error", func(t *testing.T) {
t.Parallel()
a := newDecodeError("Byte", nil)
require.NoError(t, a)
})
t.Run("newDecodeWithCodeError", func(t *testing.T) {
t.Parallel()
a := newDecodeWithCodeError("Byte", 1)
require.Error(t, a)
assert.Equal(t, "failed to decode Byte, invalid code: 1", a.Error())
})
t.Run("newDecodeGenericError", func(t *testing.T) {
t.Parallel()
a := newDecodeGenericError[int](errTest)
require.Error(t, a)
assert.Equal(t, "failed to decode Generic[int]: some error", a.Error())
})
t.Run("newDecodeGenericError without error", func(t *testing.T) {
t.Parallel()
a := newDecodeGenericError[int](nil)
require.NoError(t, a)
})
}