You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
=== RUN TestClientDefaultHttpClient
--- FAIL: TestClientDefaultHttpClient (0.00s)
panic: interface conversion: http.RoundTripper is nil, not *http.Transport [recovered]
panic: interface conversion: http.RoundTripper is nil, not *http.Transport
goroutine 34 [running]:
testing.tRunner.func1(0xc4202bc2d0)
/usr/local/go/src/testing/testing.go:711 +0x2d2
panic(0x19f5ee0, 0xc42070c480)
/usr/local/go/src/runtime/panic.go:491 +0x283
github.com/hashicorp/vault/api.NewClient(0xc42070c440, 0xc42070c440, 0xc400000008, 0xc4201980c0)
/Users/fatih/go/src/github.com/hashicorp/vault/api/client.go:271 +0x379
github.com/hashicorp/vault/api.TestClientDefaultHttpClient(0xc4202bc2d0)
/Users/fatih/go/src/github.com/hashicorp/vault/api/client_test.go:51 +0x5c
testing.tRunner(0xc4202bc2d0, 0x1b696f8)
/usr/local/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:789 +0x2de
exit status 2
FAIL github.com/hashicorp/vault/api 0.163s
Important Factoids:
This because of the following code in NewClient() that tries to access .Transport directly:
tp := c.HttpClient.Transport.(*http.Transport)
The Go doc for this http.Client has the following:
type Client struct {
// Transport specifies the mechanism by which individual
// HTTP requests are made.
// If nil, DefaultTransport is used.
Transport RoundTripper
...
}
However the statement If nil, DefaultTransport is used, is only valid inside the net/http package. The net/http has the following method internally that makes sure it returns a non-nil transport (from $GOROOT/src/net/http/client.go:192:
Expected Behavior:
I should be able to construct a Go client instance with Go's
http.DefaultClient
Actual Behavior:
The client doesn't return an error and just panics.
Steps to Reproduce:
Add the following to
api/client_test.go
and rungo test
you should see the following
Important Factoids:
This because of the following code in
NewClient()
that tries to access.Transport
directly:The Go doc for this
http.Client
has the following:However the statement
If nil, DefaultTransport is used
, is only valid inside thenet/http
package. The net/http has the following method internally that makes sure it returns a non-nil transport (from$GOROOT/src/net/http/client.go:192
:References:
When I've tried to fix it by passing a
http.DefaultTransport
, I've encountered another issue, which is reported here: #3435The text was updated successfully, but these errors were encountered: