Skip to content

Commit

Permalink
test that we no longer use the http.DefaultClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Sep 12, 2017
1 parent 50bc684 commit 3f5acc5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions get_http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package getter

import (
"errors"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -182,6 +183,38 @@ func TestHttpGetter_authNetrc(t *testing.T) {
}
}

// test round tripper that only returns an error
type errRoundTripper struct{}

func (errRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
return nil, errors.New("test round tripper")
}

// verify that the default httpClient no longer comes from http.DefaultClient
func TestHttpGetter_cleanhttp(t *testing.T) {
ln := testHttpServer(t)
defer ln.Close()

// break the default http client
http.DefaultClient.Transport = errRoundTripper{}
defer func() {
http.DefaultClient.Transport = http.DefaultTransport
}()

g := new(HttpGetter)
dst := tempDir(t)

var u url.URL
u.Scheme = "http"
u.Host = ln.Addr().String()
u.Path = "/header"

// Get it!
if err := g.Get(dst, &u); err != nil {
t.Fatalf("err: %s", err)
}
}

func testHttpServer(t *testing.T) net.Listener {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
Expand Down

0 comments on commit 3f5acc5

Please sign in to comment.