-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_test.go
62 lines (47 loc) · 1.29 KB
/
router_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
package bone
import (
"context"
"net/http"
"testing"
)
type endpointForRouterTest struct{}
func (*endpointForRouterTest) Test(ctx context.Context, req any) (rsp any, err error) {
return struct{}{}, nil
}
var _ Endpoint = (*endpointForRouterTest)(nil)
type transportForRouterTest struct {
Router *Router `inject:"application.router"`
Endpoint *endpointForRouterTest `inject:""`
}
func (t *transportForRouterTest) Register() error {
t.Router.Methods(http.MethodGet).Path("/").Handler(NewServer(t.Endpoint.Test, nil, EncodeJSONResponse))
return nil
}
var _ Transport = (*transportForRouterTest)(nil)
type moduleForRouterTest struct {
Transport *transportForRouterTest `inject:""`
}
func (*moduleForRouterTest) Name() string {
return "module.test"
}
func (*moduleForRouterTest) Init() error {
return nil
}
func (*moduleForRouterTest) Register() error {
return nil
}
func (*moduleForRouterTest) Unregister() error {
return nil
}
var _ Module = (*moduleForRouterTest)(nil)
func TestRegisterRouter(t *testing.T) {
options := DefaultApplicationOptions()
application := NewApplication(options)
application.Use(new(moduleForRouterTest))
go application.Run()
rsp, err := http.Get("http://127.0.0.1:8080/")
if err != nil || rsp.StatusCode == http.StatusOK {
t.Log(err)
t.Fail()
}
}