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

Golang mocks.SetAcceptedHeaders函数代码示例

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

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



在下文中一共展示了SetAcceptedHeaders函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:ahmetalpbalkan,项目名称:go-autorest,代码行数:25,代码来源:client_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: 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:ahmetalpbalkan,项目名称:go-autorest,代码行数:8,代码来源:autorest_test.go


示例4: 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:ahmetalpbalkan,项目名称:go-autorest,代码行数:8,代码来源:autorest_test.go


示例5: 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


示例6: 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


示例7: TestNewPollingRequestProvidesTheURL

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

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


示例8: 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


示例9: TestGetRetryAfter

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

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


示例10: 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:ahmetalpbalkan,项目名称:go-autorest,代码行数:9,代码来源:autorest_test.go


示例11: TestNewPollingRequestLeavesBodyOpenWhenPrepareFails

func TestNewPollingRequestLeavesBodyOpenWhenPrepareFails(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	resp.Header.Set(http.CanonicalHeaderKey(headerLocation), testBadURL)

	_, err := NewPollingRequest(resp, NullAuthorizer{})
	if !resp.Body.(*mocks.Body).IsOpen() {
		t.Errorf("autorest: NewPollingRequest closed the http.Request Body when Prepare returned an error (%v)", err)
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:autorest_test.go


示例12: TestNewPollingRequestReturnsAnErrorWhenPrepareFails

func TestNewPollingRequestReturnsAnErrorWhenPrepareFails(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	resp.Header.Set(http.CanonicalHeaderKey(HeaderLocation), mocks.TestBadURL)

	_, err := NewPollingRequest(resp, nil)
	if err == nil {
		t.Fatal("autorest: NewPollingRequest failed to return an error when Prepare fails")
	}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:10,代码来源:autorest_test.go


示例13: TestNewPollingRequestDoesNotReturnARequestWhenPrepareFails

func TestNewPollingRequestDoesNotReturnARequestWhenPrepareFails(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	resp.Header.Set(http.CanonicalHeaderKey(HeaderLocation), mocks.TestBadURL)

	req, _ := NewPollingRequest(resp, nil)
	if req != nil {
		t.Fatal("autorest: NewPollingRequest returned an http.Request when Prepare failed")
	}
}
开发者ID:Azure,项目名称:go-autorest,代码行数:10,代码来源:autorest_test.go


示例14: TestNewPollingRequestAppliesAuthorization

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

	req, _ := NewPollingRequest(resp, mockAuthorizer{})
	if req.Header.Get(http.CanonicalHeaderKey(headerAuthorization)) != testAuthorizationHeader {
		t.Errorf("autorest: NewPollingRequest did not apply authorization -- received %v, expected %v",
			req.Header.Get(http.CanonicalHeaderKey(headerAuthorization)), testAuthorizationHeader)
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:10,代码来源:autorest_test.go


示例15: TestGetRetryAfterReturnsDefaultDelayIfRetryHeaderIsMalformed

func TestGetRetryAfterReturnsDefaultDelayIfRetryHeaderIsMalformed(t *testing.T) {
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	resp.Header.Set(http.CanonicalHeaderKey(HeaderRetryAfter), "a very bad non-integer value")

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


示例16: TestPollingReturnsNoErrorForUnexpectedStatusCode

func TestPollingReturnsNoErrorForUnexpectedStatusCode(t *testing.T) {
	client := mocks.NewSender()
	client.EmitStatus("500 InternalServerError", http.StatusInternalServerError)

	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})

	resp, err := PollForAttempts(client, req, time.Duration(0), 1, http.StatusAccepted)
	if err != nil {
		t.Error("autorest: Polling emitted error for unknown status code")
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:14,代码来源:autorest_test.go


示例17: TestPollForAttemptsStops

func TestPollForAttemptsStops(t *testing.T) {
	client := mocks.NewSender()
	client.EmitErrors(-1)

	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})

	PollForAttempts(client, req, time.Duration(0), 5)
	if client.Attempts() < 5 || client.Attempts() > 5 {
		t.Errorf("autorest: PollForAttempts stopped incorrectly -- expected %v attempts, actual attempts were %v", 5, client.Attempts())
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:14,代码来源:autorest_test.go


示例18: TestPollingReturnsDefaultsToAcceptedStatusCode

func TestPollingReturnsDefaultsToAcceptedStatusCode(t *testing.T) {
	client := mocks.NewSender()

	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	client.SetResponse(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})

	resp, err := PollForAttempts(client, req, time.Duration(0), 1)
	if err == nil {
		t.Error("autorest: Polling failed to default to HTTP 202")
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:14,代码来源:autorest_test.go


示例19: TestPollingLeavesFinalBodyOpen

func TestPollingLeavesFinalBodyOpen(t *testing.T) {
	client := mocks.NewSender()
	client.EmitStatus("500 InternalServerError", http.StatusInternalServerError)

	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})

	resp, _ = PollForAttempts(client, req, time.Duration(0), 1)
	if !resp.Body.(*mocks.Body).IsOpen() {
		t.Error("autorest: Polling unexpectedly closed the response body")
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:14,代码来源:autorest_test.go


示例20: TestDecorateForPollingCloseBodyOnEachAttempt

func TestDecorateForPollingCloseBodyOnEachAttempt(t *testing.T) {
	client := mocks.NewSender()

	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	client.SetResponse(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})
	resp, _ = PollForAttempts(client, req, time.Duration(0), 5)
	if resp.Body.(*mocks.Body).CloseAttempts() < 5 {
		t.Errorf("autorest: decorateForPolling failed to close the response Body between requests -- expected %v, received %v",
			5, resp.Body.(*mocks.Body).CloseAttempts())
	}
}
开发者ID:ahmetalpbalkan,项目名称:go-autorest,代码行数:14,代码来源:autorest_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang to.BoolPtr函数代码示例发布时间:2022-05-24
下一篇:
Golang mocks.NewSender函数代码示例发布时间: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