mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #12737 from davidlanouette/12718
client v2: check for empty request from the context
This commit is contained in:
commit
102096ade2
@ -521,15 +521,22 @@ type simpleHTTPClient struct {
|
||||
headerTimeout time.Duration
|
||||
}
|
||||
|
||||
// ErrNoRequest indicates that the HTTPRequest object could not be found
|
||||
// or was nil. No processing could continue.
|
||||
var ErrNoRequest = errors.New("No HTTPRequest was available")
|
||||
|
||||
func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) {
|
||||
req := act.HTTPRequest(c.endpoint)
|
||||
if req == nil {
|
||||
return nil, nil, ErrNoRequest
|
||||
}
|
||||
|
||||
if err := printcURL(req); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
isWait := false
|
||||
if req != nil && req.URL != nil {
|
||||
if req.URL != nil {
|
||||
ws := req.URL.Query().Get("wait")
|
||||
if len(ws) != 0 {
|
||||
var err error
|
||||
|
@ -158,6 +158,24 @@ func TestSimpleHTTPClientDoError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type nilAction struct{}
|
||||
|
||||
func (a *nilAction) HTTPRequest(url.URL) *http.Request {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSimpleHTTPClientDoNilRequest(t *testing.T) {
|
||||
tr := newFakeTransport()
|
||||
c := &simpleHTTPClient{transport: tr}
|
||||
|
||||
tr.errchan <- errors.New("fixture")
|
||||
|
||||
_, _, err := c.Do(context.Background(), &nilAction{})
|
||||
if err != ErrNoRequest {
|
||||
t.Fatalf("expected non-nil error, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleHTTPClientDoCancelContext(t *testing.T) {
|
||||
tr := newFakeTransport()
|
||||
c := &simpleHTTPClient{transport: tr}
|
||||
|
Loading…
x
Reference in New Issue
Block a user