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


Golang mocks.SetAcceptedHeaders函數代碼示例

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


在下文中一共展示了SetAcceptedHeaders函數的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: 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

示例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:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:8,代碼來源:autorest_test.go

示例4: 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:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:autorest_test.go

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

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

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

示例8: TestNewPollingRequestReturnsAGetRequest

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

	req, _ := NewPollingRequest(resp, NullAuthorizer{})
	if req.Method != "GET" {
		t.Errorf("autorest: NewPollingRequest did not create an HTTP GET request -- actual method %v", req.Method)
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:autorest_test.go

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

示例10: 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:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:10,代碼來源:autorest_test.go

示例11: TestNewPollingRequestDoesNotReturnARequestWhenPrepareFails

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

	req, _ := NewPollingRequest(resp, NullAuthorizer{})
	if req != nil {
		t.Error("autorest: NewPollingRequest returned an http.Request when Prepare failed")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:10,代碼來源:autorest_test.go

示例12: 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:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:10,代碼來源:autorest_test.go

示例13: TestGetPollingDelayReturnsDefaultDelayIfRetryHeaderIsMalformed

func TestGetPollingDelayReturnsDefaultDelayIfRetryHeaderIsMalformed(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 := GetPollingDelay(resp, DefaultPollingDelay)
	if d != DefaultPollingDelay {
		t.Errorf("autorest: GetPollingDelay failed to returned the default delay for a malformed Retry-After header -- expected %v, received %v",
			DefaultPollingDelay, d)
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:autorest_test.go

示例14: 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:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:14,代碼來源:autorest_test.go

示例15: 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:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:14,代碼來源:autorest_test.go


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