10 "github.com/opentracing/opentracing-go"
12 "github.com/go-kit/kit/log"
13 "github.com/go-kit/kit/metrics/discard"
15 "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint"
16 "github.com/go-kit/kit/examples/addsvc/pkg/addservice"
17 "github.com/go-kit/kit/examples/addsvc/pkg/addtransport"
20 func TestHTTP(t *testing.T) {
21 svc := addservice.New(log.NewNopLogger(), discard.NewCounter(), discard.NewCounter())
22 eps := addendpoint.New(svc, log.NewNopLogger(), discard.NewHistogram(), opentracing.GlobalTracer())
23 mux := addtransport.NewHTTPHandler(eps, opentracing.GlobalTracer(), log.NewNopLogger())
24 srv := httptest.NewServer(mux)
27 for _, testcase := range []struct {
28 method, url, body, want string
30 {"GET", srv.URL + "/concat", `{"a":"1","b":"2"}`, `{"v":"12"}`},
31 {"GET", srv.URL + "/sum", `{"a":1,"b":2}`, `{"v":3}`},
33 req, _ := http.NewRequest(testcase.method, testcase.url, strings.NewReader(testcase.body))
34 resp, _ := http.DefaultClient.Do(req)
35 body, _ := ioutil.ReadAll(resp.Body)
36 if want, have := testcase.want, strings.TrimSpace(string(body)); want != have {
37 t.Errorf("%s %s %s: want %q, have %q", testcase.method, testcase.url, testcase.body, want, have)