-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathroutes_test.go
More file actions
52 lines (41 loc) · 1.33 KB
/
routes_test.go
File metadata and controls
52 lines (41 loc) · 1.33 KB
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
package httpserver
import (
"net/http"
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func Test_newDefaultRoutes(t *testing.T) {
t.Parallel()
cfg := defaultConfig()
cfg.defaultEnabledRoutes = allDefaultRoutes()
cfg.metricsHandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {}
cfg.pingHandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {}
cfg.pprofHandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {}
cfg.statusHandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {}
cfg.ipHandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {}
cfg.disableDefaultRouteLogger[IndexRoute] = true
cfg.disableDefaultRouteLogger[IPRoute] = true
cfg.disableDefaultRouteLogger[MetricsRoute] = true
cfg.disableDefaultRouteLogger[PingRoute] = true
cfg.disableDefaultRouteLogger[PprofRoute] = true
cfg.disableDefaultRouteLogger[StatusRoute] = true
routes := newDefaultRoutes(cfg)
expFuncs := []http.HandlerFunc{
cfg.metricsHandlerFunc,
cfg.pingHandlerFunc,
cfg.pprofHandlerFunc,
cfg.statusHandlerFunc,
cfg.ipHandlerFunc,
}
boundCount := 0
for _, expFn := range expFuncs {
for _, r := range routes {
if reflect.ValueOf(expFn).Pointer() == reflect.ValueOf(r.Handler).Pointer() {
boundCount++
require.True(t, r.DisableLogger, r.Path)
}
}
}
require.Equal(t, 5, boundCount)
}