OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package lhttp | 5 package lhttp |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/json" | 9 "encoding/json" |
10 "errors" | 10 "errors" |
11 "fmt" | 11 "fmt" |
12 "io" | 12 "io" |
13 "io/ioutil" | 13 "io/ioutil" |
14 "net/http" | 14 "net/http" |
15 "net/http/httptest" | 15 "net/http/httptest" |
16 "testing" | 16 "testing" |
17 "time" | 17 "time" |
18 | 18 |
19 » "github.com/luci/luci-go/client/internal/retry" | 19 » "github.com/luci/luci-go/common/retry" |
20 "github.com/maruel/ut" | 20 "github.com/maruel/ut" |
21 ) | 21 ) |
22 | 22 |
23 func TestNewRequestGET(t *testing.T) { | 23 func TestNewRequestGET(t *testing.T) { |
24 // First call returns HTTP 500, second succeeds. | 24 // First call returns HTTP 500, second succeeds. |
25 serverCalls := 0 | 25 serverCalls := 0 |
26 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r
*http.Request) { | 26 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r
*http.Request) { |
27 serverCalls++ | 27 serverCalls++ |
28 content, err := ioutil.ReadAll(r.Body) | 28 content, err := ioutil.ReadAll(r.Body) |
29 ut.ExpectEqual(t, nil, err) | 29 ut.ExpectEqual(t, nil, err) |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 defer r.Body.Close() | 266 defer r.Body.Close() |
267 out := handler(r.Body) | 267 out := handler(r.Body) |
268 if out == nil { | 268 if out == nil { |
269 w.WriteHeader(500) | 269 w.WriteHeader(500) |
270 } else { | 270 } else { |
271 w.Header().Set("Content-Type", jsonContentType) | 271 w.Header().Set("Content-Type", jsonContentType) |
272 ut.ExpectEqual(t, nil, json.NewEncoder(w).Encode(out)) | 272 ut.ExpectEqual(t, nil, json.NewEncoder(w).Encode(out)) |
273 } | 273 } |
274 }) | 274 }) |
275 } | 275 } |
OLD | NEW |