-
Notifications
You must be signed in to change notification settings - Fork 1
/
meter_test.go
49 lines (38 loc) · 928 Bytes
/
meter_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
package metrics
import (
"net/http"
"net/url"
"testing"
"github.com/nbio/st"
"gopkg.in/vinxi/utils.v0"
)
func TestMeter(t *testing.T) {
metrics := &Meter{
meters: Meters,
metrics: NewMetrics(),
quit: make(chan bool),
}
defer metrics.Stop()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("foo"))
})
rw := utils.NewWriterStub()
req := &http.Request{Header: make(http.Header), URL: &url.URL{Host: "foo.com"}}
metrics.measureHTTP(handler)(rw, req)
st.Expect(t, rw.Code, 200)
rw = utils.NewWriterStub()
req = &http.Request{Header: make(http.Header), URL: &url.URL{Host: "foo.com"}}
metrics.measureHTTP(handler)(rw, req)
}
type writerStub struct {
code int
data string
}
func (w *writerStub) WriteHeader(code int) {
w.code = code
}
func (w *writerStub) Write(data []byte) (int, error) {
w.data = string(data)
return 0, nil
}