-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind_test.go
More file actions
executable file
·88 lines (74 loc) · 1.77 KB
/
bind_test.go
File metadata and controls
executable file
·88 lines (74 loc) · 1.77 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
package di_test
import (
"fmt"
"testing"
"time"
"github.com/jad21/di"
)
// type testSt struct {
// Msg string
// Num int
// }
func TestBind(t *testing.T) {
di := di.New()
test1 := testSt{Msg: time.Now().String(), Num: 666}
o := di.Map(test1)
if o != nil {
t.Errorf("expected nil on mapping test1, got %v", o)
}
fmt.Printf("test1: %+v\n", test1)
var test2 testSt
override := di.Resolve(&test2)
if test1 != test2 {
t.Errorf("expected test2 == test1, got %+v != %+v", test2, test1)
}
fmt.Printf("override: %v, test2: %+v\n", override, test2)
// No
var test3 testSt
override = di.Resolve(test3)
if override == nil {
t.Error("expected override to be not nil for test3 (by value)")
}
fmt.Printf("override: %v, test3: %+v\n", override, test3)
test5 := &testSt{Msg: time.Now().String(), Num: 666}
o = di.Map(test5)
if o != nil {
t.Errorf("expected nil on mapping test5, got %v", o)
}
// No
var test4 *testSt
err := di.Resolve(test4)
if err == nil {
t.Error("expected error for test4 (nil pointer)")
}
fmt.Printf("err: %v, test4: %+v\n", err, test4)
var test6 *testSt
err = di.Resolve(&test6)
if err != nil {
t.Errorf("expected no error for test6, got %v", err)
}
if test5 != test6 {
t.Errorf("expected test6 == test5, got %+v != %+v", test6, test5)
}
fmt.Printf("err: %v, test6: %+v\n", err, test6)
}
func TestApply(t *testing.T) {
di := di.New()
val := time.Now().String()
o := di.Map(val)
if o != nil {
t.Errorf("expected nil on mapping val, got %v", o)
}
var v testSt
err := di.Apply(&v)
if err != nil {
t.Errorf("expected nil error on Apply testSt, got %v", err)
}
t.Logf("val: %s, v: %+v", val, v)
var s string
err = di.Apply(&s)
if err != nil {
t.Errorf("expected nil error on Apply string, got %v", err)
}
t.Logf("s: %s", s)
}