当前位置: 首页>>代码示例>>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;未经允许,请勿转载。