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

Golang api.MockedTransporter类代码示例

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

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



在下文中一共展示了MockedTransporter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestRequest_Update_Update

func TestRequest_Update_Update(t *testing.T) {

	resource := MakeResourceAt("people")
	resource.Set("name", "Mat").Set("age", 29)

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response
	response := NewTestResponse(200, nil, nil, "", api.ChangeInfo(map[string]interface{}{common.ChangeInfoPublicFieldCreated: 1, common.ChangeInfoPublicFieldDeltas: []interface{}{map[string]interface{}{common.DataFieldID: "hello", common.ChangeInfoPublicFieldDeltaCreated: 123}}}))
	mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	changeInfo, err := session.At("people").Update(resource)

	if assert.NoError(t, err) {
		if assert.NotNil(t, changeInfo) {
			mockedTransporter.AssertExpectations(t)
			request := mockedTransporter.Calls[0].Arguments[0].(*api.Request)

			assert.Equal(t, request.HTTPMethod(), common.HTTPMethodPatch)
			assert.Equal(t, request.Path(), "people")
			assert.Equal(t, changeInfo.Created(), 1)
		}
	}

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:28,代码来源:request_actions_test.go


示例2: TestRequest_Delete

/*
	Delete
*/
func TestRequest_Delete(t *testing.T) {

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response
	response := NewTestResponse(200, nil, nil, "", api.ChangeInfo(map[string]interface{}{common.ChangeInfoPublicFieldDeleted: 5}))
	mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	changeInfo, err := session.At("people/123").Delete()

	if assert.NoError(t, err) {
		assert.NotNil(t, changeInfo)
	}

	mockedTransporter.AssertExpectations(t)
	request := mockedTransporter.Calls[0].Arguments[0].(*api.Request)

	assert.Equal(t, request.HTTPMethod(), common.HTTPMethodDelete)
	assert.Equal(t, request.Path(), "people/123")
	assert.Equal(t, request.Body(), []byte(""))

	assert.Equal(t, changeInfo.Deleted(), 5)

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:30,代码来源:request_actions_test.go


示例3: TestRequest_ReadOne

func TestRequest_ReadOne(t *testing.T) {

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response
	response := NewTestResponse(200, map[string]interface{}{"~data": []interface{}{map[string]interface{}{"name": "Mat"}}}, nil, "", nil)
	mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	resource, err := session.At("people/123").ReadOne()

	if assert.NoError(t, err) {
		assert.NotNil(t, resource)
	}

	mockedTransporter.AssertExpectations(t)
	request := mockedTransporter.Calls[0].Arguments[0].(*api.Request)

	assert.Equal(t, request.HTTPMethod(), common.HTTPMethodGet)
	assert.Equal(t, request.Path(), "people/123")
	assert.Equal(t, request.Body(), []byte(""))

	assert.Equal(t, resource.ResourceData()["name"], response.BodyObject().Data().(map[string]interface{})["~data"].([]interface{})[0].(map[string]interface{})["name"])
	assert.Equal(t, resource.ResourcePath(), "people/123")

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:28,代码来源:request_actions_test.go


示例4: TestRequest_CreateMany

func TestRequest_CreateMany(t *testing.T) {

	var resources []*Resource

	resource := MakeResourceAt("people")
	resource.Set("name", "Mat").Set("age", 29)
	resources = append(resources, resource)
	resource = MakeResourceAt("people")
	resource.Set("name", "Tyler").Set("age", 28)
	resources = append(resources, resource)
	resource = MakeResourceAt("people")
	resource.Set("name", "Stacey").Set("age", 29)
	resources = append(resources, resource)

	resourceCollection := NewResourceCollection(resources)

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response
	response := NewTestResponse(200, nil, nil, "", api.ChangeInfo(map[string]interface{}{common.ChangeInfoPublicFieldCreated: 3, common.ChangeInfoPublicFieldDeltas: []interface{}{
		map[string]interface{}{common.DataFieldID: "hello", common.ChangeInfoPublicFieldDeltaCreated: 123},
		map[string]interface{}{common.DataFieldID: "goodbye", common.ChangeInfoPublicFieldDeltaCreated: 456},
		map[string]interface{}{common.DataFieldID: "greetings", common.ChangeInfoPublicFieldDeltaCreated: 789}}}))
	mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	changeInfo, err := session.At("people").CreateMany(resourceCollection)

	if assert.NoError(t, err) {
		if assert.NotNil(t, changeInfo) {
			mockedTransporter.AssertExpectations(t)
			request := mockedTransporter.Calls[0].Arguments[0].(*api.Request)

			assert.Equal(t, request.HTTPMethod(), common.HTTPMethodPost)
			assert.Equal(t, request.Path(), "people")
			assert.Equal(t, changeInfo.Created(), 3)

			assert.Equal(t, resourceCollection.Resources[0].ID(), "hello")
			assert.Equal(t, resourceCollection.Resources[0].ResourceData()[common.ChangeInfoPublicFieldDeltaCreated].(float64), 123)
			assert.Equal(t, resourceCollection.Resources[1].ID(), "goodbye")
			assert.Equal(t, resourceCollection.Resources[1].ResourceData()[common.ChangeInfoPublicFieldDeltaCreated].(float64), 456)
			assert.Equal(t, resourceCollection.Resources[2].ID(), "greetings")
			assert.Equal(t, resourceCollection.Resources[2].ResourceData()[common.ChangeInfoPublicFieldDeltaCreated].(float64), 789)
		}
	}

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:49,代码来源:request_actions_test.go


示例5: TestStrongResources_UsingTheResource

/*

	This shows how you can use your strongly typed resource in place
	of the normal Resource object with zero effort

	The mockedTransporter stuff is just so our call to "Create" doesn't
	actually try to hit any servers.

*/
func TestStrongResources_UsingTheResource(t *testing.T) {

	// make a session object
	session := NewSession("project", "company", "apiKey")

	// don't make real requests
	mockedTransporter := new(api.MockedTransporter)
	session.SetTransporter(mockedTransporter)
	mockedTransporter.On("MakeRequest", mock.Anything).Return(nil, assert.AnError)

	// make a person resource
	p := MakePersonResource("123")

	//... and use it as normal
	session.At(p.ResourcePath()).Create(p)

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:26,代码来源:strong_resources_test.go


示例6: TestRequest_ReadOne_ReadError

func TestRequest_ReadOne_ReadError(t *testing.T) {

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response
	mockedTransporter.On("MakeRequest", mock.Anything).Return(nil, assert.AnError)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	resource, err := session.At("people/123").ReadOne()

	if assert.Nil(t, resource) {
		assert.Equal(t, assert.AnError, err)
	}

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:17,代码来源:request_actions_test.go


示例7: TestRequest_ReadOne_StretchrError

func TestRequest_ReadOne_StretchrError(t *testing.T) {

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response
	response := NewTestResponse(500, nil, []map[string]interface{}{map[string]interface{}{"~message": "Something went wrong"}}, "", nil)
	mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	resource, err := session.At("people/123").ReadOne()

	if assert.Nil(t, resource) {
		assert.Equal(t, "Something went wrong", fmt.Sprintf("%s", err))
	}

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:18,代码来源:request_actions_test.go


示例8: TestRequest_ReadMany_WithTotal

func TestRequest_ReadMany_WithTotal(t *testing.T) {

	mockedTransporter := new(api.MockedTransporter)
	api.ActiveLiveTransporter = mockedTransporter

	// make a response

	responseData := map[string]interface{}{"~count": 2, common.ResponseObjectFieldTotal: 500, "~data": []interface{}{map[string]interface{}{"name": "Mat", common.DataFieldID: "ABC"},
		map[string]interface{}{"name": "Tyler", common.DataFieldID: "DEF"}}}

	response := NewTestResponse(200, responseData, nil, "", nil)
	mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil)

	session := NewSession(TestProjectName, TestAccountName, TestAPIKey)

	resourceCollection, err := session.At("people").ReadMany()

	if assert.NoError(t, err) {
		assert.Equal(t, 2, len(resourceCollection.Resources))
	}

	mockedTransporter.AssertExpectations(t)
	request := mockedTransporter.Calls[0].Arguments[0].(*api.Request)

	assert.Equal(t, request.HTTPMethod(), common.HTTPMethodGet)
	assert.Equal(t, request.Path(), "people")
	assert.Equal(t, request.Body(), []byte(""))

	assert.Equal(t, resourceCollection.Total, 500)

	resource1 := resourceCollection.Resources[0]
	resource2 := resourceCollection.Resources[1]

	assert.Equal(t, resource1.ResourceData()["name"], response.BodyObject().Data().(map[string]interface{})["~data"].([]interface{})[0].(map[string]interface{})["name"])
	assert.Equal(t, resource2.ResourceData()["name"], response.BodyObject().Data().(map[string]interface{})["~data"].([]interface{})[1].(map[string]interface{})["name"])
	assert.Equal(t, resource1.ResourcePath(), "people/ABC")
	assert.Equal(t, resource2.ResourcePath(), "people/DEF")
	assert.Equal(t, resource1.ResourcePath(), "people/ABC")
	assert.Equal(t, resource2.ResourcePath(), "people/DEF")

}
开发者ID:stretchr,项目名称:sdk-go,代码行数:41,代码来源:request_actions_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.CallerInfo函数代码示例发布时间:2022-05-28
下一篇:
Golang objx.Map类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap