-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.go
75 lines (65 loc) · 1.52 KB
/
app_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
package eudore_test
import (
"context"
"errors"
"testing"
. "github.com/eudore/eudore"
. "github.com/eudore/eudore/middleware"
_ "golang.org/x/tools/cover"
)
func init() {
DefaultLoggerFormatterFormatTime = "none"
DefaultRouterLoggerKind = "~all|metadata"
}
func TestAppRun(*testing.T) {
app := NewApp()
app.SetValue(ContextKeyLogger, NewLogger(&LoggerConfig{
Stdout: true,
StdColor: true,
HookMeta: true,
}))
app.SetValue(ContextKeyRender, HandlerDataRenderJSON)
app.SetValue(ContextKeyContextPool, NewContextBasePool(app))
app.AddMiddleware(HandlerEmpty)
app.AddMiddleware("global", HandlerEmpty)
app.GetFunc("/health", NewHealthCheckFunc(app))
app.GetFunc("/hello", func(ctx Context) {
ctx.WriteString("hello eudore")
})
keys := []any{
ContextKeyApp,
ContextKeyAppCancel,
ContextKeyAppValues,
ContextKeyLogger,
ContextKeyConfig,
ContextKeyClient,
ContextKeyRouter,
}
for _, k := range keys {
app.Value(k)
}
app.SetValue("stop-hook", Unmounter(func(context.Context) {
app.Info("stop-hook")
}))
app.NewRequest("GET", "/health")
app.Parse()
app.ParseOption(func(context.Context, Config) error {
return errors.New("parse error")
})
app.Parse()
app.SetValue(ContextKeyError, "stop app")
app.CancelFunc()
app.Run()
}
func TestAppListen(*testing.T) {
app := NewApp()
app.Listen(":8088")
app.Listen(":8088")
app.Listen(":8089")
app.ListenTLS(":8088", "", "")
app.ListenTLS(":8090", "", "")
app.Listen("localhost")
app.ListenTLS("localhost", "", "")
app.CancelFunc()
app.Run()
}