-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault_test.go
89 lines (60 loc) · 1.67 KB
/
default_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
81
82
83
84
85
86
87
88
89
// Copyright 2018 Axel Etcheverry. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package service
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDefaultContainer(t *testing.T) {
assert.False(t, Has("test.bad.service.name"))
assert.Equal(t, []string{}, GetKeys())
Set("my.service", func(c Container) interface{} {
return &MyService{}
})
Extend("my.service", func(s *MyService, c Container) *MyService {
s.Name = "My Service"
return s
})
assert.True(t, Has("my.service"))
assert.Equal(t, []string{"my.service"}, GetKeys())
Set("my.service", func(c Container) interface{} {
return &MyService{}
})
myService1 := Get("my.service").(*MyService)
myService2 := Get("my.service").(*MyService)
assert.Equal(t, myService1, myService2)
assert.Equal(t, "My Service", myService1.Name)
assert.Panics(t, func() {
Set("my.service", func(c Container) interface{} {
return &MyService{}
})
})
assert.Panics(t, func() {
Extend("my.service", func(s *MyService, c Container) *MyService {
s.Name = "My Service 2"
return s
})
})
assert.Panics(t, func() {
Extend("not.exists.service", func(s *MyService, c Container) *MyService {
s.Name = "My Service 3"
return s
})
})
assert.Panics(t, func() {
Get("test.bad.service.name")
})
var myService3 *MyService
Fill("my.service", &myService3)
assert.Equal(t, myService2, myService3)
assert.Panics(t, func() {
var bad string
Fill("my.service", &bad)
})
SetValue("my.static.value", "bar")
assert.Equal(t, "bar", Get("my.static.value"))
assert.Panics(t, func() {
SetValue("my.static.value", "bar")
})
}