OSDN Git Service

delete miner
[bytom/vapor.git] / vendor / github.com / go-kit / kit / examples / addsvc / cmd / addsvc / wiring_test.go
1 package main
2
3 import (
4         "io/ioutil"
5         "net/http"
6         "net/http/httptest"
7         "strings"
8         "testing"
9
10         "github.com/opentracing/opentracing-go"
11
12         "github.com/go-kit/kit/log"
13         "github.com/go-kit/kit/metrics/discard"
14
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"
18 )
19
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)
25         defer srv.Close()
26
27         for _, testcase := range []struct {
28                 method, url, body, want string
29         }{
30                 {"GET", srv.URL + "/concat", `{"a":"1","b":"2"}`, `{"v":"12"}`},
31                 {"GET", srv.URL + "/sum", `{"a":1,"b":2}`, `{"v":3}`},
32         } {
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)
38                 }
39         }
40 }