/usr/share/gocode/src/github.com/opentracing-contrib/go-stdlib/nethttp/server_test.go is in golang-github-opentracing-contrib-go-stdlib-dev 0.0~git20170528.48e4d76-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 50 51 | package nethttp
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/opentracing/opentracing-go/mocktracer"
)
func TestOperationNameOption(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/root", func(w http.ResponseWriter, r *http.Request) {})
fn := func(r *http.Request) string {
return "HTTP " + r.Method + ": /root"
}
tests := []struct {
options []MWOption
opName string
}{
{nil, "HTTP GET"},
{[]MWOption{OperationNameFunc(fn)}, "HTTP GET: /root"},
}
for _, tt := range tests {
testCase := tt
t.Run(testCase.opName, func(t *testing.T) {
tr := &mocktracer.MockTracer{}
mw := Middleware(tr, mux, testCase.options...)
srv := httptest.NewServer(mw)
defer srv.Close()
_, err := http.Get(srv.URL)
if err != nil {
t.Fatalf("server returned error: %v", err)
}
spans := tr.FinishedSpans()
if got, want := len(spans), 1; got != want {
t.Fatalf("got %d spans, expected %d", got, want)
}
if got, want := spans[0].OperationName, testCase.opName; got != want {
t.Fatalf("got %s operation name, expected %s", got, want)
}
})
}
}
|