-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_details_test.go
51 lines (46 loc) · 1.34 KB
/
error_details_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
package errkit_test
import (
"testing"
qt "github.com/frankban/quicktest"
"github.com/kanisterio/errkit"
)
type testStruct struct {
Foo string
Bar int
Baz *testStruct
}
func TestToErrorDetails(t *testing.T) {
cases := []struct {
testName string
args []any
expected errkit.ErrorDetails
}{
{
testName: "ErrorDetails as an argument",
args: []any{errkit.ErrorDetails{"key": "value"}},
expected: errkit.ErrorDetails{"key": "value"},
},
{
testName: "Sequence of keys and values of any type",
args: []any{"string_key", "string value", "int key", 123, "struct key", testStruct{Foo: "aaa", Bar: 123, Baz: &testStruct{Foo: "bbb", Bar: 234}}},
expected: errkit.ErrorDetails{"string_key": "string value", "int key": 123, "struct key": testStruct{Foo: "aaa", Bar: 123, Baz: &testStruct{Foo: "bbb", Bar: 234}}},
},
{
testName: "Odd number of arguments",
args: []any{"key_1", 1, "key_2"},
expected: errkit.ErrorDetails{"key_1": 1, "key_2": "NOVAL"},
},
{
testName: "Argument which is supposed to be a key is not a string",
args: []any{123, 456},
expected: errkit.ErrorDetails{"BADKEY:(123)": 456},
},
}
for _, tc := range cases {
t.Run(tc.testName, func(t *testing.T) {
c := qt.New(t)
result := errkit.ToErrorDetails(tc.args)
c.Assert(result, qt.DeepEquals, tc.expected)
})
}
}