-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph_assert_test.go
63 lines (47 loc) · 1002 Bytes
/
graph_assert_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package inj
import (
"fmt"
"testing"
)
type AssertionTester struct {
S string `inj:""`
I int `inj:""`
}
func Test_AssertionHappyPath(t *testing.T) {
g := NewGraph()
g.Provide(&AssertionTester{}, "hello", 1)
if v, m := g.Assert(); !v {
fmt.Println(m)
t.Error("Assert() failed")
}
}
func Test_AssertionComplexHappyPath(t *testing.T) {
g, c := NewGraph(), ConcreteType{}
// Register providers (can include non-providers, which will then be wired up)
if err := g.Provide(
&c,
&helloSayer{},
&goodbyeSayer{},
funcInstance,
ichannel,
DEFAULT_STRING,
); err != nil {
t.Fatalf("Graph.Provide: %s", err)
}
if v, m := g.Assert(); !v {
fmt.Println(m)
t.Error("Assert() failed")
}
}
func Test_AssertionSadPath(t *testing.T) {
g := NewGraph()
// Only provide the concrete type
g.Provide(&AssertionTester{})
v, m := g.Assert()
if v {
t.Error("Assert() didn't fail")
}
if g, e := len(m), 2; g != e {
t.Errorf("Expected %d errors, got %d", e, g)
}
}