-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_internal_test.go
More file actions
68 lines (59 loc) · 1.32 KB
/
utils_internal_test.go
File metadata and controls
68 lines (59 loc) · 1.32 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
// SPDX-FileCopyrightText: 2026 The DMorph contributors.
// SPDX-License-Identifier: MPL-2.0
package dmorph_test
import (
"errors"
"fmt"
"testing"
"github.com/AlphaOne1/dmorph"
)
func TestWrapError(t *testing.T) {
t.Parallel()
tests := []struct {
err error
text string
wantErr bool
wantErrMsg string
}{
{ // 0
text: "wrap this",
err: errors.New("original error"),
wantErr: true,
wantErrMsg: "wrap this: original error",
},
{ // 1
text: "wrap that: %w",
err: errors.New("original error"),
wantErr: true,
wantErrMsg: "wrap that: %w: original error",
},
{ // 2
text: "wrap this",
err: nil,
wantErr: false,
},
{ // 3
text: "",
err: errors.New("error case"),
wantErr: true,
wantErrMsg: "error case",
},
{ // 4
text: "",
err: nil,
wantErr: false,
},
}
for testIndex, test := range tests {
t.Run(fmt.Sprintf("WrapError-%d", testIndex), func(t *testing.T) {
t.Parallel()
got := dmorph.TwrapIfError(test.text, test.err)
if (got != nil) != test.wantErr {
t.Errorf(`got error "%v", but wanted "%v"`, got, test.wantErr)
}
if test.wantErr && got.Error() != test.wantErrMsg {
t.Errorf(`got error "%v" but wanted "%v"`, got.Error(), test.wantErrMsg)
}
})
}
}