• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang mocks.NewResponse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestCreateResponderDoesNotModify

func TestCreateResponderDoesNotModify(t *testing.T) {
	r1 := mocks.NewResponse()
	r2 := mocks.NewResponse()
	p := CreateResponder()
	err := p.Respond(r1)
	if err != nil {
		t.Errorf("autorest: CreateResponder failed (%v)", err)
	}
	if !reflect.DeepEqual(r1, r2) {
		t.Errorf("autorest: CreateResponder without decorators modified the response")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:12,代码来源:responder_test.go


示例2: TestDoPollForStatusCodes_CanBeCanceled

func TestDoPollForStatusCodes_CanBeCanceled(t *testing.T) {
	cancel := make(chan struct{})
	delay := 5 * time.Second

	r := mocks.NewResponse()
	mocks.SetAcceptedHeaders(r)
	client := mocks.NewSender()
	client.AppendAndRepeatResponse(r, 100)

	var wg sync.WaitGroup
	wg.Add(1)
	start := time.Now()
	go func() {
		wg.Done()
		r, _ := SendWithSender(client, mocks.NewRequest(),
			DoPollForStatusCodes(time.Millisecond, time.Millisecond, http.StatusAccepted))
		Respond(r,
			ByClosing())
	}()
	wg.Wait()
	close(cancel)
	time.Sleep(5 * time.Millisecond)
	if time.Since(start) >= delay {
		t.Fatalf("autorest: Sender#DoPollForStatusCodes failed to cancel")
	}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:26,代码来源:sender_test.go


示例3: TestGetAsyncOperation_ReturnsEmptyStringIfHeaderIsAbsent

func TestGetAsyncOperation_ReturnsEmptyStringIfHeaderIsAbsent(t *testing.T) {
	r := mocks.NewResponse()

	if len(getAsyncOperation(r)) != 0 {
		t.Fatalf("azure: getAsyncOperation failed to return empty string when the Azure-AsyncOperation header is absent -- received %v", getAsyncOperation(r))
	}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:7,代码来源:async_test.go


示例4: TestResponseRequiresPollingIgnoresSuccess

func TestResponseRequiresPollingIgnoresSuccess(t *testing.T) {
	resp := mocks.NewResponse()

	if ResponseRequiresPolling(resp) {
		t.Error("autorest: ResponseRequiresPolling did not ignore a successful response")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:7,代码来源:autorest_test.go


示例5: TestResponseRequiresPollingLeavesBodyOpen

func TestResponseRequiresPollingLeavesBodyOpen(t *testing.T) {
	resp := mocks.NewResponse()

	ResponseRequiresPolling(resp)
	if !resp.Body.(*mocks.Body).IsOpen() {
		t.Error("autorest: ResponseRequiresPolling closed the responise body while ignoring a successful response")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:8,代码来源:autorest_test.go


示例6: TestClientShouldPollIgnoredPollingMode

func TestClientShouldPollIgnoredPollingMode(t *testing.T) {
	c := &Client{PollingMode: DoNotPoll}
	r := mocks.NewResponse()

	if c.ShouldPoll(r) {
		t.Error("autorest: Client#ShouldPoll failed to return false when polling is disabled")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:8,代码来源:client_test.go


示例7: TestClientShouldPollIgnoresOk

func TestClientShouldPollIgnoresOk(t *testing.T) {
	c := &Client{PollingMode: PollUntilAttempts}
	r := mocks.NewResponse()

	if c.ShouldPoll(r) {
		t.Error("autorest: Client#ShouldPoll failed to return false for an http.Response that does not require polling")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:8,代码来源:client_test.go


示例8: TestByIgnoring

func TestByIgnoring(t *testing.T) {
	r := mocks.NewResponse()

	Respond(r,
		(func() RespondDecorator {
			return func(r Responder) Responder {
				return ResponderFunc(func(r2 *http.Response) error {
					r1 := mocks.NewResponse()
					if !reflect.DeepEqual(r1, r2) {
						t.Errorf("autorest: ByIgnoring modified the HTTP Response -- received %v, expected %v", r2, r1)
					}
					return nil
				})
			}
		})(),
		ByIgnoring(),
		ByClosing())
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:18,代码来源:responder_test.go


示例9: TestUpdatePollingState_ClosesTheOriginalResponseBody

func TestUpdatePollingState_ClosesTheOriginalResponseBody(t *testing.T) {
	resp := mocks.NewResponse()
	b := resp.Body.(*mocks.Body)
	ps := &pollingState{responseFormat: usesProvisioningStatus}
	updatePollingState(resp, ps)
	if b.IsOpen() {
		t.Fatal("azure: updatePollingState failed to close the original http.Response Body")
	}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:9,代码来源:async_test.go


示例10: TestExtractHeaderValueHandlesMissingHeader

func TestExtractHeaderValueHandlesMissingHeader(t *testing.T) {
	r := mocks.NewResponse()
	v := ""

	if ExtractHeaderValue(mocks.TestHeader, r) != v {
		t.Errorf("autorest: ExtractHeader failed to retrieve the expected header -- expected [%s]%v, received [%s]%v",
			mocks.TestHeader, v, mocks.TestHeader, ExtractHeaderValue(mocks.TestHeader, r))
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:9,代码来源:responder_test.go


示例11: TestExtractHeaderHandlesMissingHeader

func TestExtractHeaderHandlesMissingHeader(t *testing.T) {
	var v []string
	r := mocks.NewResponse()

	if !reflect.DeepEqual(ExtractHeader(mocks.TestHeader, r), v) {
		t.Errorf("autorest: ExtractHeader failed to handle a missing header -- expected %v, received %v",
			v, ExtractHeader(mocks.TestHeader, r))
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:9,代码来源:responder_test.go


示例12: TestClientIsPollingAllowedIgnoresOk

func TestClientIsPollingAllowedIgnoresOk(t *testing.T) {
	c := Client{PollingMode: PollUntilAttempts}
	r := mocks.NewResponse()

	err := c.IsPollingAllowed(r)
	if err != nil {
		t.Error("autorest: Client#IsPollingAllowed returned an error for an http.Response that does not require polling")
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:9,代码来源:client_test.go


示例13: TestByClosingIfErrorDoesNotClosesIfNoErrorOccurs

func TestByClosingIfErrorDoesNotClosesIfNoErrorOccurs(t *testing.T) {
	r := mocks.NewResponse()
	Respond(r,
		ByClosingIfError())

	if !r.Body.(*mocks.Body).IsOpen() {
		t.Errorf("autorest: ByClosingIfError closed the response body even though no error occurred")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:9,代码来源:responder_test.go


示例14: TestExtractHeader

func TestExtractHeader(t *testing.T) {
	r := mocks.NewResponse()
	v := []string{"v1", "v2", "v3"}
	mocks.SetResponseHeaderValues(r, mocks.TestHeader, v)

	if !reflect.DeepEqual(ExtractHeader(mocks.TestHeader, r), v) {
		t.Errorf("autorest: ExtractHeader failed to retrieve the expected header -- expected [%s]%v, received [%s]%v",
			mocks.TestHeader, v, mocks.TestHeader, ExtractHeader(mocks.TestHeader, r))
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:responder_test.go


示例15: TestResponseGetPollingLocation

func TestResponseGetPollingLocation(t *testing.T) {
	r := mocks.NewResponse()
	mocks.SetLocationHeader(r, mocks.TestURL)
	ar := Response{Response: r}

	if ar.GetPollingLocation() != mocks.TestURL {
		t.Errorf("autorest: Response#GetPollingLocation failed to return correct URL -- expected %v, received %v",
			mocks.TestURL, ar.GetPollingLocation())
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:client_test.go


示例16: TestResponseGetPollingDelayReturnsDefault

func TestResponseGetPollingDelayReturnsDefault(t *testing.T) {
	ar := Response{Response: mocks.NewResponse()}

	d1 := 10 * time.Second
	d2 := ar.GetPollingDelay(d1)
	if d1 != d2 {
		t.Errorf("autorest: Response#GetPollingDelay failed to return the default delay -- expected %v, received %v",
			d1, d2)
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:client_test.go


示例17: TestExtractHeaderValue

func TestExtractHeaderValue(t *testing.T) {
	r := mocks.NewResponse()
	v := "v1"
	mocks.SetResponseHeader(r, mocks.TestHeader, v)

	if ExtractHeaderValue(mocks.TestHeader, r) != v {
		t.Fatalf("autorest: ExtractHeader failed to retrieve the expected header -- expected [%s]%v, received [%s]%v",
			mocks.TestHeader, v, mocks.TestHeader, ExtractHeaderValue(mocks.TestHeader, r))
	}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:10,代码来源:responder_test.go


示例18: TestExtractRequestID

func TestExtractRequestID(t *testing.T) {
	uuid := "71FDB9F4-5E49-4C12-B266-DE7B4FD999A6"
	resp := mocks.NewResponse()
	mocks.SetResponseHeader(resp, HeaderRequestID, uuid)

	if ExtractRequestID(resp) != uuid {
		t.Errorf("azure: ExtractRequestID failed to extract the %s -- expected %s, received %s",
			HeaderRequestID, uuid, ExtractRequestID(resp))
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:azure_test.go


示例19: TestExtractHeaderValueRetrievesFirstValue

func TestExtractHeaderValueRetrievesFirstValue(t *testing.T) {
	r := mocks.NewResponse()
	v := []string{"v1", "v2", "v3"}
	mocks.SetResponseHeaderValues(r, mocks.TestHeader, v)

	if ExtractHeaderValue(mocks.TestHeader, r) != v[0] {
		t.Errorf("autorest: ExtractHeader failed to retrieve the expected header -- expected [%s]%v, received [%s]%v",
			mocks.TestHeader, v[0], mocks.TestHeader, ExtractHeaderValue(mocks.TestHeader, r))
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:responder_test.go


示例20: TestByClosing

func TestByClosing(t *testing.T) {
	r := mocks.NewResponse()
	err := Respond(r, ByClosing())
	if err != nil {
		t.Errorf("autorest: ByClosing failed (%v)", err)
	}
	if r.Body.(*mocks.Body).IsOpen() {
		t.Errorf("autorest: ByClosing did not close the response body")
	}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:10,代码来源:responder_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mocks.NewResponseWithContent函数代码示例发布时间:2022-05-24
下一篇:
Golang mocks.NewRequest函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap