-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathhandler_test.go
More file actions
35 lines (30 loc) · 849 Bytes
/
handler_test.go
File metadata and controls
35 lines (30 loc) · 849 Bytes
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
// +build go1.7
package xstats
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandler(t *testing.T) {
s := &fakeSender{}
n := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
xs, ok := FromRequest(r).(*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.ServeHTTP(nil, &http.Request{})
}
func TestHandlerPrefix(t *testing.T) {
s := &fakeSender{}
n := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
xs, ok := FromRequest(r).(*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.ServeHTTP(nil, &http.Request{})
}