当前位置: 首页>>代码示例>>Golang>>正文


Golang TestServerInterface.GetHTTPClient方法代码示例

本文整理汇总了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)
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:10,代码来源:admin_test.go

示例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
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:41,代码来源:status_test.go


注:本文中的github.com/cockroachdb/cockroach/testutils/serverutils.TestServerInterface.GetHTTPClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。