本文整理匯總了Golang中github.com/cockroachdb/cockroach/testutils/serverutils.TestServerInterface.GetHTTPClient方法的典型用法代碼示例。如果您正苦於以下問題:Golang TestServerInterface.GetHTTPClient方法的具體用法?Golang TestServerInterface.GetHTTPClient怎麽用?Golang TestServerInterface.GetHTTPClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/testutils/serverutils.TestServerInterface
的用法示例。
在下文中一共展示了TestServerInterface.GetHTTPClient方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: apiPost
// apiPost issues a POST to the provided server using the given API path and
// request, marshalling the result into response.
func apiPost(s serverutils.TestServerInterface, path string, request, response proto.Message) error {
apiPath := apiEndpoint + path
client, err := s.GetHTTPClient()
if err != nil {
return err
}
return util.PostJSON(client, s.AdminURL()+apiPath, request, response)
}
示例2: getRequestReader
// getRequestReader returns the io.ReadCloser from a get request to the test
// server with the given path. The returned closer should be closed by the
// caller.
func getRequestReader(t *testing.T, ts serverutils.TestServerInterface, path string) io.ReadCloser {
httpClient, err := ts.GetHTTPClient()
if err != nil {
t.Fatal(err)
}
url := ts.AdminURL() + path
for r := retry.Start(retryOptions); r.Next(); {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatal(err)
}
req.Header.Set(util.AcceptHeader, util.JSONContentType)
resp, err := httpClient.Do(req)
if err != nil {
log.Infof("could not GET %s - %s", url, err)
continue
}
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Infof("could not read body for %s - %s", url, err)
continue
}
log.Infof("could not GET %s - statuscode: %d - body: %s", url, resp.StatusCode, body)
continue
}
returnedContentType := resp.Header.Get(util.ContentTypeHeader)
if returnedContentType != util.JSONContentType {
log.Infof("unexpected content type: %v", returnedContentType)
continue
}
log.Infof("OK response from %s", url)
return resp.Body
}
t.Fatalf("There was an error retrieving %s", url)
return nil
}