-
Notifications
You must be signed in to change notification settings - Fork 35
/
manager_test.go
108 lines (87 loc) · 2.12 KB
/
manager_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package endly_test
import (
"github.com/stretchr/testify/assert"
"github.com/viant/endly"
_ "github.com/viant/endly/service/shared"
"github.com/viant/toolbox"
"testing"
)
func TestNewManager(t *testing.T) {
manager := endly.New()
context := manager.NewContext(toolbox.NewContext())
manager.Register(newTestService())
service, err := manager.Service("testService")
assert.Nil(t, err)
assert.NotNil(t, service)
_, err = manager.Service("cc")
assert.NotNil(t, err)
manager2, err := context.Manager()
assert.Nil(t, err)
assert.Equal(t, manager2, manager)
{
service, err := manager2.Service("testService")
assert.Nil(t, err)
assert.NotNil(t, service)
}
{
service, err := context.Service("testService")
assert.Nil(t, err)
assert.NotNil(t, service)
}
{
state := context.State()
assert.NotNil(t, state)
state.Put("k1", 1)
}
{
state := context.State()
assert.Equal(t, 1, state.GetInt("k1"))
}
}
type testService struct {
*endly.AbstractService
}
func (t *testService) Run(context *endly.Context, request interface{}) *endly.ServiceResponse {
return &endly.ServiceResponse{}
}
func newTestService() endly.Service {
var result = &testService{
AbstractService: endly.NewAbstractService("testService"),
}
result.AbstractService.Service = result
return result
}
func Test_ServiceRoutes(t *testing.T) {
manager := endly.New()
var services = endly.Services(manager)
var context = manager.NewContext(toolbox.NewContext())
for _, service := range services {
response := service.Run(context, struct{}{})
assert.True(t, response.Error != "")
for _, action := range service.Actions() {
if route, err := service.Route(action); err == nil {
if route.Handler != nil {
_, err := route.Handler(context, struct{}{})
assert.NotNil(t, err)
}
}
}
}
}
func TestNewManager_Run(t *testing.T) {
manager := endly.New()
{
_, err := manager.Run(nil, &endly.NopRequest{})
if assert.Nil(t, err) {
}
}
{
_, err := manager.Run(nil, &struct{}{})
if assert.NotNil(t, err) {
}
}
}
func Test_GetVersion(t *testing.T) {
version := endly.GetVersion()
assert.True(t, version != "")
}