-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
37 lines (32 loc) · 865 Bytes
/
Copy patherrors_test.go
File metadata and controls
37 lines (32 loc) · 865 Bytes
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
package env
import (
"errors"
"testing"
)
// TestSentinelErrors checks that validation failures are testable with
// errors.Is against the exported sentinel errors.
func TestSentinelErrors(t *testing.T) {
var empty struct{}
notStruct := 5
cases := []struct {
name string
err error
want error
}{
{"nil object", Unmarshal(nil), ErrNilObject},
{"not a pointer", Unmarshal(struct {
X int `env:"X"`
}{}), ErrNotPointer},
{"not a struct", Unmarshal(¬Struct), ErrNotStruct},
{"empty struct", Unmarshal(&empty), ErrEmptyStruct},
}
for _, c := range cases {
if !errors.Is(c.err, c.want) {
t.Errorf("%s: expected %v, got %v", c.name, c.want, c.err)
}
}
// Marshal with a non-struct value.
if err := Marshal(5); !errors.Is(err, ErrInvalidObject) {
t.Errorf("marshal non-struct: expected %v, got %v", ErrInvalidObject, err)
}
}