Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: common/lhttp/client_test.go

Issue 1159563002: Move retry and lhttp packages from client/internal to common/. (Closed) Base URL: git@github.com:luci/luci-go@master
Patch Set: move-retry-http Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/lhttp/client.go ('k') | common/lhttp/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « common/lhttp/client.go ('k') | common/lhttp/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698