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


Golang mocks.NewResponseWithStatus函数代码示例

本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/mocks.NewResponseWithStatus函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResponseWithStatus函数的具体用法?Golang NewResponseWithStatus怎么用?Golang NewResponseWithStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewResponseWithStatus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestClientPollAsNeededPollsForDuration

func TestClientPollAsNeededPollsForDuration(t *testing.T) {
	c := Client{}
	c.PollingMode = PollUntilDuration
	c.PollingDuration = 10 * time.Millisecond

	s := mocks.NewSender()
	s.EmitStatus("202 Accepted", http.StatusAccepted)
	c.Sender = s

	r := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(r)
	s.SetResponse(r)

	d1 := 10 * time.Millisecond
	start := time.Now()
	resp, _ := c.PollAsNeeded(r)
	d2 := time.Now().Sub(start)
	if d2 < d1 {
		t.Errorf("autorest: Client#PollAsNeeded did not poll for the expected duration -- expected %v, actual %v",
			d1.Seconds(), d2.Seconds())
	}

	Respond(resp,
		ByClosing())
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:25,代码来源:client_test.go

示例2: TestResponseRequiresPollingReturnsFalseForUnexpectedStatusCodes

func TestResponseRequiresPollingReturnsFalseForUnexpectedStatusCodes(t *testing.T) {
	resp := mocks.NewResponseWithStatus("500 InternalServerError", http.StatusInternalServerError)
	mocks.SetAcceptedHeaders(resp)

	if ResponseRequiresPolling(resp) {
		t.Error("autorest: ResponseRequiresPolling did not return false when ignoring a status code")
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:8,代码来源:autorest_test.go

示例3: TestNewPollingRequestLeavesBodyOpenWhenLocationHeaderIsMissing

func TestNewPollingRequestLeavesBodyOpenWhenLocationHeaderIsMissing(t *testing.T) {
	resp := mocks.NewResponseWithStatus("500 InternalServerError", http.StatusInternalServerError)

	NewPollingRequest(resp, NullAuthorizer{})
	if !resp.Body.(*mocks.Body).IsOpen() {
		t.Error("autorest: NewPollingRequest closed the http.Request Body when the Location header was missing")
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:8,代码来源:autorest_test.go

示例4: TestGetPollingLocationReturnsEmptyStringForMissingLocation

func TestGetPollingLocationReturnsEmptyStringForMissingLocation(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)

	l := GetPollingLocation(resp)
	if len(l) != 0 {
		t.Errorf("autorest: GetPollingLocation return a value without a Location header -- received %v", l)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:8,代码来源:autorest_test.go

示例5: TestNewPollingRequestDoesNotReturnARequestWhenLocationHeaderIsMissing

func TestNewPollingRequestDoesNotReturnARequestWhenLocationHeaderIsMissing(t *testing.T) {
	resp := mocks.NewResponseWithStatus("500 InternalServerError", http.StatusInternalServerError)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})
	if req != nil {
		t.Error("autorest: NewPollingRequest returned an http.Request when the Location header was missing")
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:8,代码来源:autorest_test.go

示例6: TestResponseRequiresPollingDefaultsToAcceptedStatusCode

func TestResponseRequiresPollingDefaultsToAcceptedStatusCode(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	if !ResponseRequiresPolling(resp) {
		t.Error("autorest: ResponseRequiresPolling failed to create a request for default 202 Accepted status code")
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:8,代码来源:autorest_test.go

示例7: TestNewPollingRequestClosesTheResponseBody

func TestNewPollingRequestClosesTheResponseBody(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	NewPollingRequest(resp, NullAuthorizer{})
	if resp.Body.(*mocks.Body).IsOpen() {
		t.Error("autorest: NewPollingRequest failed to close the response body when creating a new request")
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:autorest_test.go

示例8: Do

func (s *Senders) Do(req *http.Request) (*http.Response, error) {
	if len(*s) == 0 {
		response := mocks.NewResponseWithStatus("", http.StatusInternalServerError)
		return response, fmt.Errorf("no sender for %q", req.URL)
	}
	sender := (*s)[0]
	*s = (*s)[1:]
	return sender.Do(req)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:senders.go

示例9: TestClientIsPollingAllowed

func TestClientIsPollingAllowed(t *testing.T) {
	c := Client{PollingMode: PollUntilAttempts}
	r := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)

	err := c.IsPollingAllowed(r)
	if err != nil {
		t.Errorf("autorest: Client#IsPollingAllowed returned an error for an http.Response that requires polling (%v)", err)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:client_test.go

示例10: TestClientIsPollingAllowedIgnoresDisabledForIgnoredStatusCode

func TestClientIsPollingAllowedIgnoresDisabledForIgnoredStatusCode(t *testing.T) {
	c := Client{PollingMode: PollUntilAttempts}
	r := mocks.NewResponseWithStatus("400 BadRequest", http.StatusBadRequest)

	err := c.IsPollingAllowed(r)
	if err != nil {
		t.Errorf("autorest: Client#IsPollingAllowed returned an error for an http.Response that requires polling (%v)", err)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:client_test.go

示例11: TestClientIsPollingAllowedIgnoredPollingMode

func TestClientIsPollingAllowedIgnoredPollingMode(t *testing.T) {
	c := Client{PollingMode: DoNotPoll}
	r := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)

	err := c.IsPollingAllowed(r)
	if err == nil {
		t.Error("autorest: Client#IsPollingAllowed failed to return an error when polling is disabled")
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:client_test.go

示例12: TestGetPollingDelayReturnsDefaultDelayIfRetryHeaderIsMissing

func TestGetPollingDelayReturnsDefaultDelayIfRetryHeaderIsMissing(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)

	d := GetPollingDelay(resp, DefaultPollingDelay)
	if d != DefaultPollingDelay {
		t.Errorf("autorest: GetPollingDelay failed to returned the default delay for a missing Retry-After header -- expected %v, received %v",
			DefaultPollingDelay, d)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:autorest_test.go

示例13: TestGetPollingDelay

func TestGetPollingDelay(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	d := GetPollingDelay(resp, DefaultPollingDelay)
	if d != mocks.TestDelay {
		t.Errorf("autorest: GetPollingDelay failed to returned the expected delay -- expected %v, received %v", mocks.TestDelay, d)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:autorest_test.go

示例14: TestGetPollingLocation

func TestGetPollingLocation(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	l := GetPollingLocation(resp)
	if len(l) == 0 {
		t.Errorf("autorest: GetPollingLocation failed to return Location header -- expected %v, received %v", mocks.TestURL, l)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:autorest_test.go

示例15: TestNewPollingRequestProvidesTheURL

func TestNewPollingRequestProvidesTheURL(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})
	if req.URL.String() != mocks.TestURL {
		t.Errorf("autorest: NewPollingRequest did not create an HTTP with the expected URL -- received %v, expected %v", req.URL, mocks.TestURL)
	}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:9,代码来源:autorest_test.go


注:本文中的github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/mocks.NewResponseWithStatus函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。