-
Notifications
You must be signed in to change notification settings - Fork 2
/
overrides_error_test.go
45 lines (37 loc) · 1.56 KB
/
overrides_error_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
package nject
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOverridesError(t *testing.T) {
type someType string
type anotherType string
getThing := func(_ anotherType) (someType, error) { return "", nil }
danger := Required(func(inner func(someType), param anotherType) error {
thing, err := getThing(param)
if err != nil {
return err
}
inner(thing)
return nil
})
finalWithError := func() error { return nil }
returnsTerminal := Required(func() TerminalError { return nil })
finalWithoutError := func() {}
var target func(anotherType) error
t.Log("test: okay because no error bubbling up")
//nolint:testifylint
assert.NoError(t, Sequence("A", danger, finalWithoutError).Bind(&target, nil))
t.Log("test: should fail because the final function returns error that gets clobbered")
//nolint:testifylint
assert.Error(t, Sequence("B", danger, finalWithError).Bind(&target, nil))
t.Log("test: should fail because there is a terminal-error injector that gets clobbered")
//nolint:testifylint
assert.Error(t, Sequence("C", danger, returnsTerminal, finalWithoutError).Bind(&target, nil))
t.Log("test: okay because marked even though the final function returns error that gets clobbered")
//nolint:testifylint
assert.NoError(t, Sequence("B", OverridesError(danger), finalWithError).Bind(&target, nil))
t.Log("test: okay because marked even though there is a terminal-error injector that gets clobbered")
//nolint:testifylint
assert.NoError(t, Sequence("C", OverridesError(danger), returnsTerminal, finalWithoutError).Bind(&target, nil))
}