gotsrpc/instrumentation_test.go
Stefan Martinov adae02a23f
feat: update go-modules and add objectives to summary vectors (#21)
- add instrumentation handler to allow handling stats
2019-10-25 12:32:32 +02:00

39 lines
760 B
Go

package gotsrpc
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInstrumentedService(t *testing.T) {
middleware := func(w http.ResponseWriter, r *http.Request) {
if s := GetStatsForRequest(r); s != nil {
s.Func = "func"
s.Package = "package"
s.Service = "service"
}
return
}
t.Run("stats", func(t *testing.T) {
count := 0
handler := InstrumentedService(middleware, func(s *CallStats) {
assert.Equal(t, "func", s.Func)
assert.Equal(t, "package", s.Package)
assert.Equal(t, "service", s.Service)
assert.NotNil(t, s)
count++
})
rsp := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/test", nil)
handler(rsp, req)
assert.Equal(t, 1, count)
})
}