-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
89 lines (72 loc) · 3.4 KB
/
Copy patherrors_test.go
File metadata and controls
89 lines (72 loc) · 3.4 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
package libconfig_test
import (
"fmt"
"reflect"
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/jrudder/libconfig"
)
func TestErrCannotParseEnv(t *testing.T) {
cause := fmt.Errorf("some error")
err := libconfig.NewErrCannotParseEnv(cause, reflect.Int, "key", "value")
require.Equal(t, "cannot parse env [key] with value [value] to kind [int]: some error", err.Error(), "error string must match")
}
func TestErrCannotParseEnvWithoutCause(t *testing.T) {
err := libconfig.NewErrCannotParseEnv(nil, reflect.Int, "key", "value")
require.Equal(t, "cannot parse env [key] with value [value] to kind [int]", err.Error(), "error string must match")
}
func TestErrCannotParseEnvCause(t *testing.T) {
expected := errors.New("some error")
err := libconfig.NewErrCannotParseEnv(expected, reflect.Int, "key", "value")
cause := errors.Cause(err)
require.Equal(t, expected, cause, "ErrCannotParseEnv must have a cause")
}
func TestErrCannotSetKind(t *testing.T) {
err := libconfig.NewErrCannotSetKind(reflect.Interface)
require.Equal(t, "cannot set kind [interface]", err.Error(), "error string must match")
}
func TestErrDecodeFailure(t *testing.T) {
cause := fmt.Errorf("some error")
err := libconfig.NewErrDecodeFailure(cause, "key", "value", "base64")
require.Equal(t, "failed to decode var [key] with value [value] as [base64]: some error", err.Error(), "error string must match")
}
func TestErrDecodeFailureWithoutCause(t *testing.T) {
err := libconfig.NewErrDecodeFailure(nil, "key", "value", "base64")
require.Equal(t, "failed to decode var [key] with value [value] as [base64]", err.Error(), "error string must match")
}
func TestErrDecodeFailureCause(t *testing.T) {
expected := errors.New("some error")
err := libconfig.NewErrDecodeFailure(expected, "key", "value", "base64")
cause := errors.Cause(err)
require.Equal(t, expected, cause, "ErrDecodeFailure must have a cause")
}
func TestErrInvalidConfigType(t *testing.T) {
err := libconfig.NewErrInvalidConfigType(reflect.TypeOf(int(623)))
require.Equal(t, "config must be pointer to struct but got int", err.Error(), "error string must match")
}
func TestErrInvalidConfigTypePtr(t *testing.T) {
value := 623
err := libconfig.NewErrInvalidConfigType(reflect.TypeOf(&value))
require.Equal(t, "config must be pointer to struct but got *int", err.Error(), "error string must match")
}
func TestErrInvalidTagOption(t *testing.T) {
err := libconfig.NewErrInvalidTagOption("tag,here", "something")
require.Equal(t, "tag [tag,here] contains unsupported option [something]", err.Error(), "error string must match")
}
func TestErrMissingNameTag(t *testing.T) {
err := libconfig.NewErrMissingNameTag("some-tag")
require.Equal(t, "tagged field must be named but got [some-tag]", err.Error(), "error string must match")
}
func TestErrOverflow(t *testing.T) {
err := libconfig.NewErrOverflow(reflect.Int8, "key", "value")
require.Equal(t, "overflow detected trying to set field of kind [int8] to value [value] for key [key]", err.Error(), "error string must match")
}
func TestErrVarNotFound(t *testing.T) {
err := libconfig.NewErrVarNotFound("key")
require.Equal(t, "var not found for key [key]", err.Error(), "error string must match")
}
func TestErrNestedTags(t *testing.T) {
err := libconfig.NewErrNestedTags("field", "key")
require.Equal(t, "field [field] with key [key] contains one or more nested subfields", err.Error(), "error string must match")
}