-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer_test.go
More file actions
64 lines (51 loc) · 1.38 KB
/
container_test.go
File metadata and controls
64 lines (51 loc) · 1.38 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
package wire
import (
"fmt"
"strings"
"testing"
)
func TestContainer(t *testing.T) {
myFunc := func(s string, s2 string, i int) error {
if l := len(s); l != i {
return fmt.Errorf("string %s length %d, expected %d", s, l, i)
}
return nil
}
stringProvider := func() string {
t.Log("string provider was called")
return "test"
}
if err := New(stringProvider).GreedyPatch(myFunc).(func(i int) error)(4); err != nil {
t.Error(err.Error())
}
}
func TestSatisfy(t *testing.T) {
var needyFunc func(string, int, func(), func() int)
usefulDep := func(int, string) func() { return nil }
out := New("hello", 1, usefulDep, func() func() int { return nil }).GreedyPatch(needyFunc)
_ = out.(func())
}
func TestError(t *testing.T) {
out := New(func() (int, error) { return 0, fmt.Errorf("yep") }).GreedyPatch(func(int) {})
_ = out.(error)
}
type db int
func lambda(db db, in string) (string, error) {
return strings.Repeat(in, int(db)), nil
}
func TestLambdaSyntax(t *testing.T) {
deps := New()
deps.Acquire(func() (db, error) { return 2, nil })
out, err := deps.GreedyPatch(lambda).(func(string) (string, error))("hello")
t.Log("out", out)
t.Log("err", err)
}
// type hasHi struct{}
// func (hasHi) Hi() {}
// func newHi() hasHi {
// return hasHi{}
// }
// type hi interface{ Hi() }
// func TestInterface(t *testing.T) {
// New(newHi).GreedyPatch(func(hi) {}).(func())()
// }