-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdi_test.go
80 lines (60 loc) · 980 Bytes
/
di_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package di_test
import (
"context"
"time"
)
func newCircle() Shape {
return &Circle{a: 100500}
}
func newRectangle() Shape {
return &Rectangle{a: 255}
}
type Shape interface {
SetArea(int)
GetArea() int
}
type Circle struct {
a int
}
func (c *Circle) SetArea(a int) {
c.a = a
}
func (c Circle) GetArea() int {
return c.a
}
type Rectangle struct {
a int
}
func (s *Rectangle) SetArea(a int) {
s.a = a
}
func (s Rectangle) GetArea() int {
return s.a
}
func newMySQL() Database {
return &MySQL{}
}
func newMongoDB(err error) Database {
return &MongoDB{
constructErr: err,
}
}
type Database interface {
Connect() bool
}
type MySQL struct{}
func (m MySQL) Connect() bool {
return true
}
type MongoDB struct {
Shape Shape `di:"type"`
constructCalled time.Time
constructErr error
}
func (m *MongoDB) Construct(context.Context) error {
m.constructCalled = time.Now()
return m.constructErr
}
func (m *MongoDB) Connect() bool {
return true
}