Package list golang-github-go-kit-kit / 77e82e2
Fixes for go1.7 Peter Bourgon 5 years ago
2 changed file(s) with 20 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
33
44 go:
55 - 1.5.3
6 - 1.6
7 #- tip
6 - 1.6.3
7 - 1.7
8 - tip
1212 )
1313
1414 func TestServerHappyPathSingleServer(t *testing.T) {
15 originServer := httptest.NewServer(
16 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17 w.WriteHeader(http.StatusOK)
18 w.Write([]byte("hey"))
19 }))
15 originServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
16 w.WriteHeader(http.StatusOK)
17 w.Write([]byte("hey"))
18 }))
2019 defer originServer.Close()
2120 originURL, _ := url.Parse(originServer.URL)
2221
3433
3534 responseBody, _ := ioutil.ReadAll(resp.Body)
3635 if want, have := "hey", string(responseBody); want != have {
37 t.Errorf("want %d, have %d", want, have)
36 t.Errorf("want %q, have %q", want, have)
3837 }
3938 }
4039
4443 headerVal = "go-kit-proxy"
4544 )
4645
47 originServer := httptest.NewServer(
48 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
49 if want, have := headerVal, r.Header.Get(headerKey); want != have {
50 t.Errorf("want %d, have %d", want, have)
51 }
46 originServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
47 if want, have := headerVal, r.Header.Get(headerKey); want != have {
48 t.Errorf("want %q, have %q", want, have)
49 }
5250
53 w.WriteHeader(http.StatusOK)
54 w.Write([]byte("hey"))
55 }))
51 w.WriteHeader(http.StatusOK)
52 w.Write([]byte("hey"))
53 }))
5654 defer originServer.Close()
5755 originURL, _ := url.Parse(originServer.URL)
5856
7472
7573 responseBody, _ := ioutil.ReadAll(resp.Body)
7674 if want, have := "hey", string(responseBody); want != have {
77 t.Errorf("want %d, have %d", want, have)
75 t.Errorf("want %q, have %q", want, have)
7876 }
7977 }
8078
9896
9997 func TestServerOriginServerUnreachable(t *testing.T) {
10098 // create a server, then promptly shut it down
101 originServer := httptest.NewServer(
102 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
103 w.WriteHeader(http.StatusOK)
104 }))
99 originServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
100 w.WriteHeader(http.StatusOK)
101 }))
105102 originURL, _ := url.Parse(originServer.URL)
106103 originServer.Close()
107104
113110 defer proxyServer.Close()
114111
115112 resp, _ := http.Get(proxyServer.URL)
116 if want, have := http.StatusInternalServerError, resp.StatusCode; want != have {
113 if want, have := http.StatusBadGateway, resp.StatusCode; want != have {
117114 t.Errorf("want %d, have %d", want, have)
118115 }
119116 }