From c66030feada7b7c68ff450ac170244422e9ff1f5 Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Thu, 9 Jun 2022 10:47:15 +0100 Subject: [PATCH] client_test: Tests that the configured client is used for requests. Sets a delay on the test server and a timeout on the HTTP client provided to the client such that a timeout is forced. Asserts that the returned error is a context deadline exceeded. Signed-off-by: Mark Laing --- client_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client_test.go b/client_test.go index bc47acb..dea6ab4 100644 --- a/client_test.go +++ b/client_test.go @@ -141,6 +141,25 @@ func (suite *ClientSuite) TestClientdispatchRequestSignsRequest(c *gc.C) { c.Check((*server.requestHeader)["Authorization"][0], gc.Matches, "^OAuth .*") } +func (suite *ClientSuite) TestClientdispatchRequestUsesConfiguredHTTPClient(c *gc.C) { + URI := "/some/url/" + + server := newSingleServingServer(URI, "", 0, 2*time.Second) + defer server.Close() + + client, err := NewAnonymousClient(server.URL, "2.0") + c.Assert(err, jc.ErrorIsNil) + + client.HTTPClient = &http.Client{Timeout: time.Second} + + request, err := http.NewRequest("GET", server.URL+URI, nil) + c.Assert(err, jc.ErrorIsNil) + + _, err = client.dispatchRequest(request) + + c.Assert(err, gc.ErrorMatches, `Get "http://127.0.0.1:\d+/some/url/": context deadline exceeded \(Client\.Timeout exceeded while awaiting headers\)`) +} + func (suite *ClientSuite) TestClientGetFormatsGetParameters(c *gc.C) { URI, err := url.Parse("/some/url") c.Assert(err, jc.ErrorIsNil)