-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_test.go
More file actions
52 lines (45 loc) · 1.17 KB
/
error_test.go
File metadata and controls
52 lines (45 loc) · 1.17 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
package env
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrorCollection(t *testing.T) {
t.Run("Returns formatted error", func(t *testing.T) {
// given
errorCollection := ErrorCollection{
Errors: []FieldError{
{
Location: "VAR_A",
ErrorType: ErrorWrongType,
VariableType: "int",
},
{
Location: "VAR_B",
ErrorType: ErrorRequired,
VariableType: "float32",
},
{
Location: "VAR_C",
ErrorType: ErrorParserMissingType,
VariableType: "float32",
},
{
Location: "VAR_D",
ErrorType: ErrorPointerSetterMissing,
VariableType: "customBool",
},
},
}
// when
errorMsg := errorCollection.Error()
// then
expectedMsg := `Environmental variable 'VAR_A' has wrong type. Required type: 'int'
Environmental variable 'VAR_B' is unset
Parser missing for environmental variable 'VAR_C'. Required type: 'float32'
Pointer setter missing for environmental variable 'VAR_D'. Required type: 'customBool'`
assert.Equal(t, expectedMsg, errorMsg)
})
t.Run("ErrorType is error", func(t *testing.T) {
assert.NotEqual(t, "", ErrorWrongType.Error())
})
}