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


Golang mocks.NewRequest函數代碼示例

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


在下文中一共展示了NewRequest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestWithUserAgent

func TestWithUserAgent(t *testing.T) {
	r, err := Prepare(mocks.NewRequest(), WithUserAgent("User Agent Go"))
	if err != nil {
		fmt.Printf("ERROR: %v", err)
	}
	if r.Header.Get(headerUserAgent) != "User Agent Go" {
		t.Errorf("autorest: WithUserAgent failed to add header (%s=%s)", headerUserAgent, r.Header.Get(headerUserAgent))
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:preparer_test.go

示例2: TestAsContentType

func TestAsContentType(t *testing.T) {
	r, err := Prepare(mocks.NewRequest(), AsContentType("application/text"))
	if err != nil {
		fmt.Printf("ERROR: %v", err)
	}
	if r.Header.Get(headerContentType) != "application/text" {
		t.Errorf("autorest: AsContentType failed to add header (%s=%s)", headerContentType, r.Header.Get(headerContentType))
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:preparer_test.go

示例3: TestWithBearerAuthorization

func TestWithBearerAuthorization(t *testing.T) {
	r, err := Prepare(mocks.NewRequest(), WithBearerAuthorization("SOME-TOKEN"))
	if err != nil {
		fmt.Printf("ERROR: %v", err)
	}
	if r.Header.Get(headerAuthorization) != "Bearer SOME-TOKEN" {
		t.Errorf("autorest: WithBearerAuthorization failed to add header (%s=%s)", headerAuthorization, r.Header.Get(headerAuthorization))
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:preparer_test.go

示例4: TestAsJSON

func TestAsJSON(t *testing.T) {
	r, err := Prepare(mocks.NewRequest(), AsJSON())
	if err != nil {
		fmt.Printf("ERROR: %v", err)
	}
	if r.Header.Get(headerContentType) != mimeTypeJSON {
		t.Errorf("autorest: AsJSON failed to add header (%s=%s)", headerContentType, r.Header.Get(headerContentType))
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:preparer_test.go

示例5: TestWithHeaderAllocatesHeaders

func TestWithHeaderAllocatesHeaders(t *testing.T) {
	r, err := Prepare(mocks.NewRequest(), WithHeader("x-foo", "bar"))
	if err != nil {
		t.Errorf("autorest: WithHeader failed (%v)", err)
	}
	if r.Header.Get("x-foo") != "bar" {
		t.Errorf("autorest: WithHeader failed to add header (%s=%s)", "x-foo", r.Header.Get("x-foo"))
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:9,代碼來源:preparer_test.go

示例6: TestClientSendReturnsPrepareError

func TestClientSendReturnsPrepareError(t *testing.T) {
	r := mocks.NewRequest()
	s := mocks.NewSender()
	c := Client{Authorizer: mockFailingAuthorizer{}, Sender: s}

	_, err := c.Send(r)
	if err == nil {
		t.Error("autorest: Client#Send failed to return an error the Prepare error")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:10,代碼來源:client_test.go

示例7: TestClientSendSends

func TestClientSendSends(t *testing.T) {
	r := mocks.NewRequest()
	s := mocks.NewSender()
	c := Client{Sender: s}

	c.Send(r)
	if s.Attempts() <= 0 {
		t.Error("autorest: Client#Send failed to invoke the Sender")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:10,代碼來源:client_test.go

示例8: TestWithNothing

func TestWithNothing(t *testing.T) {
	r1 := mocks.NewRequest()
	r2, err := Prepare(r1, WithNothing())
	if err != nil {
		t.Errorf("autorest: WithNothing returned an unexpected error (%v)", err)
	}

	if !reflect.DeepEqual(r1, r2) {
		t.Error("azure: WithNothing modified the passed HTTP Request")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:preparer_test.go

示例9: TestClientSendInvokesInspector

func TestClientSendInvokesInspector(t *testing.T) {
	r := mocks.NewRequest()
	s := mocks.NewSender()
	i := &mockInspector{}
	c := Client{RequestInspector: i.WithInspection(), Sender: s}

	c.Send(r)
	if !i.wasInvoked {
		t.Error("autorest: Client#Send failed to invoke the RequestInspector")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:client_test.go

示例10: TestClientSendDefaultsToUsingStatusCodeOK

func TestClientSendDefaultsToUsingStatusCodeOK(t *testing.T) {
	r := mocks.NewRequest()
	s := mocks.NewSender()
	c := Client{Authorizer: mockAuthorizer{}, Sender: s}

	_, err := c.Send(r)
	if err != nil {
		t.Errorf("autorest: Client#Send returned an error for Status Code OK -- %v",
			err)
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:client_test.go

示例11: TestClientSendClosesReponseBodyWhenReturningError

func TestClientSendClosesReponseBodyWhenReturningError(t *testing.T) {
	s := mocks.NewSender()
	r := mocks.NewResponseWithStatus("500 InternalServerError", http.StatusInternalServerError)
	s.SetResponse(r)
	c := Client{Sender: s}

	c.Send(mocks.NewRequest())
	if r.Body.(*mocks.Body).IsOpen() {
		t.Error("autorest: Client#Send failed to close the response body when returning an error")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:client_test.go

示例12: TestClientSendReturnsErrorWithUnexpectedStatusCode

func TestClientSendReturnsErrorWithUnexpectedStatusCode(t *testing.T) {
	r := mocks.NewRequest()
	s := mocks.NewSender()
	s.EmitStatus("500 InternalServerError", http.StatusInternalServerError)
	c := Client{Sender: s}

	_, err := c.Send(r)
	if err == nil {
		t.Error("autorest: Client#Send failed to return an error for an unexpected Status Code")
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:client_test.go

示例13: TestClientSendDoesNotPollIfUnnecessary

func TestClientSendDoesNotPollIfUnnecessary(t *testing.T) {
	r := mocks.NewRequest()
	s := mocks.NewSender()
	c := Client{Sender: s, PollingMode: PollUntilAttempts, PollingAttempts: 10}

	c.Send(r, http.StatusOK, http.StatusAccepted)
	if s.Attempts() != 1 {
		t.Errorf("autorest: Client#Send unexpectedly polled -- attempts %d",
			s.Attempts())
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:11,代碼來源:client_test.go

示例14: TestWithAuthorizer

func TestWithAuthorizer(t *testing.T) {
	r1 := mocks.NewRequest()

	na := &NullAuthorizer{}
	r2, err := Prepare(r1,
		na.WithAuthorization())
	if err != nil {
		t.Errorf("autorest: NullAuthorizer#WithAuthorization returned an unexpected error (%v)", err)
	} else if !reflect.DeepEqual(r1, r2) {
		t.Errorf("autorest: NullAuthorizer#WithAuthorization modified the request -- received %v, expected %v", r2, r1)
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:12,代碼來源:preparer_test.go

示例15: TestClientDoSetsUserAgent

func TestClientDoSetsUserAgent(t *testing.T) {
	c := Client{UserAgent: "UserAgent"}
	r := mocks.NewRequest()

	c.Do(r)

	if r.Header.Get(http.CanonicalHeaderKey(headerUserAgent)) != "UserAgent" {
		t.Errorf("autorest: Client#Do failed to correctly set User-Agent header: %s=%s",
			http.CanonicalHeaderKey(headerUserAgent),
			r.Header.Get(http.CanonicalHeaderKey(headerUserAgent)))
	}
}
開發者ID:kbxkb,項目名稱:azure-sdk-for-go,代碼行數:12,代碼來源:client_test.go


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