本文整理匯總了Golang中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())
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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")
}
}
示例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)
}
}
示例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")
}
}
示例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")
}
}
示例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)
}
}
示例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)
}
}