/
handler_pre17_test.go
37 lines (32 loc) · 982 Bytes
/
handler_pre17_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
// +build !go1.7
package xstats
import (
"net/http"
"testing"
"github.com/rs/xhandler"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestHandler(t *testing.T) {
s := &fakeSender{}
n := xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
xs, ok := FromContext(ctx).(*xstats)
assert.True(t, ok)
assert.Equal(t, s, xs.s)
assert.Equal(t, []string{"envtag"}, xs.tags)
})
h := NewHandler(s, []string{"envtag"})(n)
h.ServeHTTPC(context.Background(), nil, nil)
}
func TestHandlerPrefix(t *testing.T) {
s := &fakeSender{}
n := xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
xs, ok := FromContext(ctx).(*xstats)
assert.True(t, ok)
assert.Equal(t, s, xs.s)
assert.Equal(t, []string{"envtag"}, xs.tags)
assert.Equal(t, "prefix.", xs.prefix)
})
h := NewHandlerPrefix(s, []string{"envtag"}, "prefix.")(n)
h.ServeHTTPC(context.Background(), nil, nil)
}