-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_test.go
49 lines (42 loc) · 1.03 KB
/
service_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
package goofy_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/urionz/goofy"
)
type TestImpl struct {
}
func (*TestImpl) Test() string {
return "test"
}
func TestApplication_AddServices(t *testing.T) {
t.Run("add service not err", func(t *testing.T) {
app := goofy.New()
require.NotPanics(t, func() {
app.AddServices(func(a goofy.Application) {
a.Provide(func() *TestImpl {
return new(TestImpl)
})
}).AddServices(func(test *TestImpl) {
require.Equal(t, "test", test.Test())
}).Run()
})
})
t.Run("add service with err should panic", func(t *testing.T) {
app := goofy.New()
require.Panics(t, func() {
app.AddServices(func(a goofy.Application) error {
return fmt.Errorf("test add service with err")
}).Run()
})
})
t.Run("when add service use not exists dep service should panic", func(t *testing.T) {
app := goofy.New()
require.Panics(t, func() {
app.AddServices(func(test *TestImpl) {
require.Equal(t, "test", test.Test())
}).Run()
})
})
}