本文整理汇总了Golang中github.com/azure/go-autorest/autorest/mocks.NewResponseWithStatus函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResponseWithStatus函数的具体用法?Golang NewResponseWithStatus怎么用?Golang NewResponseWithStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResponseWithStatus函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestGetLocation
func TestGetLocation(t *testing.T) {
resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
mocks.SetAcceptedHeaders(resp)
l := GetLocation(resp)
if len(l) == 0 {
t.Fatalf("autorest: GetLocation failed to return Location header -- expected %v, received %v", mocks.TestURL, l)
}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:9,代码来源:autorest_test.go
示例17: TestCreatePollingRequestClosesTheResponseBody
func TestCreatePollingRequestClosesTheResponseBody(t *testing.T) {
resp := mocks.NewResponseWithStatus("202 Accepted", 202)
addAcceptedHeaders(resp)
CreatePollingRequest(resp, NullAuthorizer{})
if resp.Body.(*mocks.Body).IsOpen() {
t.Error("autorest: CreatePollingRequest failed to close the response body when creating a new request")
}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:9,代码来源:autorest_test.go
示例18: TestNewPollingRequestReturnsAnErrorWhenPrepareFails
func TestNewPollingRequestReturnsAnErrorWhenPrepareFails(t *testing.T) {
resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
mocks.SetAcceptedHeaders(resp)
_, err := NewPollingRequest(resp, mockFailingAuthorizer{})
if err == nil {
t.Error("autorest: NewPollingRequest failed to return an error when Prepare fails")
}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:9,代码来源:autorest_test.go
示例19: TestNewPollingRequestReturnsAGetRequest
func TestNewPollingRequestReturnsAGetRequest(t *testing.T) {
resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
mocks.SetAcceptedHeaders(resp)
req, _ := NewPollingRequest(resp, nil)
if req.Method != "GET" {
t.Fatalf("autorest: NewPollingRequest did not create an HTTP GET request -- actual method %v", req.Method)
}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:9,代码来源:autorest_test.go
示例20: 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:ahmetalpbalkan,项目名称:go-autorest,代码行数:9,代码来源:client_test.go
注:本文中的github.com/azure/go-autorest/autorest/mocks.NewResponseWithStatus函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论