-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcontainerLineage_test.go
69 lines (52 loc) · 1.25 KB
/
containerLineage_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
package di
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParentContainer(t *testing.T) {
var err error
b, _ := NewEnhancedBuilder()
app, _ := b.Build()
_, err = app.ParentContainer()
require.NotNil(t, err)
req, _ := app.SubContainer()
parent, err := req.ParentContainer()
require.Nil(t, err)
require.Equal(t, parent, app)
}
func TestSubContainerCreation(t *testing.T) {
var err error
b, _ := NewEnhancedBuilder()
app, _ := b.Build()
request, err := app.SubContainer()
require.Nil(t, err)
subrequest, err := request.SubContainer()
require.Nil(t, err)
_, err = subrequest.SubContainer()
require.NotNil(t, err, "sub-request does not have any sub-container")
require.Equal(t, request, subrequest.Parent())
require.Equal(t, app, request.Parent())
}
func TestLineageGetterCycleError(t *testing.T) {
var err error
b, _ := NewEnhancedBuilder()
b.Add(&Def{
Name: "o-app",
Scope: App,
Build: func(ctn Container) (interface{}, error) {
ctn.Get("o-req")
return nil, nil
},
})
b.Add(&Def{
Name: "o-req",
Build: func(ctn Container) (interface{}, error) {
ctn.Get("o-app")
return nil, nil
},
})
app, _ := b.Build()
req, _ := app.SubContainer()
_, err = req.SafeGet("o-req")
require.NotNil(t, err)
}