You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
630 B
Go
26 lines
630 B
Go
4 years ago
|
package handler
|
||
4 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"testing"
|
||
|
|
||
|
"zero/core/trace/tracespec"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestTracingHandler(t *testing.T) {
|
||
|
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
|
||
|
req.Header.Set("X-Trace-ID", "theid")
|
||
|
handler := TracingHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
span, ok := r.Context().Value(tracespec.TracingKey).(tracespec.Trace)
|
||
|
assert.True(t, ok)
|
||
|
assert.Equal(t, "theid", span.TraceId())
|
||
|
}))
|
||
|
|
||
|
resp := httptest.NewRecorder()
|
||
|
handler.ServeHTTP(resp, req)
|
||
|
assert.Equal(t, http.StatusOK, resp.Code)
|
||
|
}
|