當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mocks.NewResponseWithStatus函數代碼示例

本文整理匯總了Golang中github.com/azure/go-autorest/autorest/mocks.NewResponseWithStatus函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewResponseWithStatus函數的具體用法?Golang NewResponseWithStatus怎麽用?Golang NewResponseWithStatus使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewResponseWithStatus函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestStopInstancesNotFound

func (s *environSuite) TestStopInstancesNotFound(c *gc.C) {
	env := s.openEnviron(c)
	sender0 := mocks.NewSender()
	sender0.AppendResponse(mocks.NewResponseWithStatus(
		"vm not found", http.StatusNotFound,
	))
	sender1 := mocks.NewSender()
	sender1.AppendResponse(mocks.NewResponseWithStatus(
		"vm not found", http.StatusNotFound,
	))
	s.sender = azuretesting.Senders{sender0, sender1}
	err := env.StopInstances("a", "b")
	c.Assert(err, jc.ErrorIsNil)
}
開發者ID:bac,項目名稱:juju,代碼行數:14,代碼來源:environ_test.go

示例2: newAsynchronousResponseWithError

func newAsynchronousResponseWithError() *http.Response {
	r := mocks.NewResponseWithStatus("400 Bad Request", http.StatusBadRequest)
	mocks.SetRetryHeader(r, retryDelay)
	r.Request = mocks.NewRequestForURL(mocks.TestURL)
	r.Body = mocks.NewBody(errorResponse)
	return r
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:7,代碼來源:async_test.go

示例3: TestInstanceClosePorts

func (s *instanceSuite) TestInstanceClosePorts(c *gc.C) {
	inst := s.getInstance(c)
	sender := mocks.NewSender()
	notFoundSender := mocks.NewSender()
	notFoundSender.AppendResponse(mocks.NewResponseWithStatus(
		"rule not found", http.StatusNotFound,
	))
	s.sender = azuretesting.Senders{sender, notFoundSender}

	err := inst.ClosePorts("0", []jujunetwork.PortRange{{
		Protocol: "tcp",
		FromPort: 1000,
		ToPort:   1000,
	}, {
		Protocol: "udp",
		FromPort: 1000,
		ToPort:   2000,
	}})
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(s.requests, gc.HasLen, 2)
	c.Assert(s.requests[0].Method, gc.Equals, "DELETE")
	c.Assert(s.requests[0].URL.Path, gc.Equals, securityRulePath("machine-0-tcp-1000"))
	c.Assert(s.requests[1].Method, gc.Equals, "DELETE")
	c.Assert(s.requests[1].URL.Path, gc.Equals, securityRulePath("machine-0-udp-1000-2000"))
}
開發者ID:bac,項目名稱:juju,代碼行數:26,代碼來源:instance_test.go

示例4: 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:ahmetalpbalkan,項目名稱:go-autorest,代碼行數:25,代碼來源:client_test.go

示例5: TestNewPollingRequestDoesNotReturnARequestWhenLocationHeaderIsMissing

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

	req, _ := NewPollingRequest(resp, nil)
	if req != nil {
		t.Fatal("autorest: NewPollingRequest returned an http.Request when the Location header was missing")
	}
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:8,代碼來源:autorest_test.go

示例6: TestClientShouldPoll

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

	if !c.ShouldPoll(r) {
		t.Error("autorest: Client#ShouldPoll failed to return true for an http.Response that requires polling")
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:8,代碼來源:client_test.go

示例7: TestDoRetryForStatusCodesWithSuccess

func TestDoRetryForStatusCodesWithSuccess(t *testing.T) {
	client := mocks.NewSender()
	client.AppendAndRepeatResponse(mocks.NewResponseWithStatus("408 Request Timeout", http.StatusRequestTimeout), 2)
	client.AppendResponse(mocks.NewResponseWithStatus("200 OK", http.StatusOK))

	r, _ := SendWithSender(client, mocks.NewRequest(),
		DoRetryForStatusCodes(5, time.Duration(2*time.Second), http.StatusRequestTimeout),
	)

	Respond(r,
		ByClosing())

	if client.Attempts() != 3 {
		t.Fatalf("autorest: Sender#DoRetryForStatusCodes -- Got: StatusCode %v in %v attempts; Want: StatusCode 200 OK in 2 attempts -- ",
			r.Status, client.Attempts()-1)
	}
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:17,代碼來源:sender_test.go

示例8: TestResponseRequiresPollingDefaultsToAcceptedStatusCode

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

	if !ResponseRequiresPolling(resp) {
		t.Error("autorest: ResponseRequiresPolling failed to create a request for default 202 Accepted status code")
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:8,代碼來源:autorest_test.go

示例9: TestCreatePollingRequestDoesNotReturnARequestWhenLocationHeaderIsMissing

func TestCreatePollingRequestDoesNotReturnARequestWhenLocationHeaderIsMissing(t *testing.T) {
	resp := mocks.NewResponseWithStatus("500 ServerError", 500)

	req, _ := CreatePollingRequest(resp, NullAuthorizer{})
	if req != nil {
		t.Error("autorest: CreatePollingRequest returned an http.Request when the Location header was missing")
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:8,代碼來源:autorest_test.go

示例10: TestGetLocationReturnsEmptyStringForMissingLocation

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

	l := GetLocation(resp)
	if len(l) != 0 {
		t.Fatalf("autorest: GetLocation return a value without a Location header -- received %v", l)
	}
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:8,代碼來源:autorest_test.go

示例11: TestResponseRequiresPollingReturnsFalseForUnexpectedStatusCodes

func TestResponseRequiresPollingReturnsFalseForUnexpectedStatusCodes(t *testing.T) {
	resp := mocks.NewResponseWithStatus("500 ServerError", 500)
	addAcceptedHeaders(resp)

	if ResponseRequiresPolling(resp) {
		t.Error("autorest: ResponseRequiresPolling did not return false when ignoring a status code")
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:8,代碼來源:autorest_test.go

示例12: TestCreatePollingRequestLeavesBodyOpenWhenLocationHeaderIsMissing

func TestCreatePollingRequestLeavesBodyOpenWhenLocationHeaderIsMissing(t *testing.T) {
	resp := mocks.NewResponseWithStatus("500 ServerError", 500)

	CreatePollingRequest(resp, NullAuthorizer{})
	if !resp.Body.(*mocks.Body).IsOpen() {
		t.Error("autorest: CreatePollingRequest closed the http.Request Body when the Location header was missing")
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:8,代碼來源:autorest_test.go

示例13: TestGetRetryDelayReturnsDefaultDelayIfRetryHeaderIsMissing

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

	d := GetRetryDelay(resp, DefaultPollingDelay)
	if d != DefaultPollingDelay {
		t.Errorf("autorest: GetRetryDelay failed to returned the default delay for a missing Retry-After header -- expected %v, received %v",
			DefaultPollingDelay, d)
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:9,代碼來源:autorest_test.go

示例14: TestGetRetryDelay

func TestGetRetryDelay(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", 202)
	addAcceptedHeaders(resp)

	d := GetRetryDelay(resp, DefaultPollingDelay)
	if d != testDelay {
		t.Errorf("autorest: GetRetryDelay failed to returned the expected delay -- expected %v, received %v", testDelay, d)
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:9,代碼來源:autorest_test.go

示例15: TestCreatePollingRequestProvidesTheURL

func TestCreatePollingRequestProvidesTheURL(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", 202)
	addAcceptedHeaders(resp)

	req, _ := CreatePollingRequest(resp, NullAuthorizer{})
	if req.URL.String() != testUrl {
		t.Errorf("autorest: CreatePollingRequest did not create an HTTP with the expected URL -- received %v, expected %v", req.URL, testUrl)
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:9,代碼來源:autorest_test.go


注:本文中的github.com/azure/go-autorest/autorest/mocks.NewResponseWithStatus函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。