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

Golang test.MakeTestContext函数代码示例

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

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



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

示例1: TestPipe_Handle

func TestPipe_Handle(t *testing.T) {

	ctx := context_test.MakeTestContext()

	handler1 := new(handlers_test.TestHandler)
	handler2 := new(handlers_test.TestHandler)
	handler3 := new(handlers_test.TestHandler)

	// add the handlers to the pipe
	p := Pipe{handler1, handler2, handler3}

	// setup expectations
	handler1.On("WillHandle", ctx).Return(true, nil)
	handler1.On("Handle", ctx).Return(false, nil)
	handler2.On("WillHandle", ctx).Return(false, nil)
	handler3.On("WillHandle", ctx).Return(true, nil)
	handler3.On("Handle", ctx).Return(false, nil)

	// call handle
	p.Handle(ctx)

	// assert expectations
	mock.AssertExpectationsForObjects(t, handler1.Mock, handler2.Mock, handler3.Mock)

}
开发者ID:antianlu,项目名称:goweb,代码行数:25,代码来源:pipe_test.go


示例2: TestRespondEnvelopOptions

func TestRespondEnvelopOptions(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContextWithPath("/?envelop=false")
	data := map[string]interface{}{"name": "Mat"}

	// When AlwaysEvenlopResponse = true but ?envelop=false
	API.Respond(ctx, 200, data, nil)
	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"name\":\"Mat\"}")

	// When AlwaysEvenlopResponse = false
	ctx = context_test.MakeTestContext()
	API.AlwaysEnvelopResponse = false

	API.Respond(ctx, 200, data, nil)
	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"name\":\"Mat\"}")

	// When AlwaysEvenlopResponse = false but ?envelop=true
	ctx = context_test.MakeTestContextWithPath("/?envelop=true")

	API.Respond(ctx, 200, data, nil)
	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"d\":{\"name\":\"Mat\"},\"s\":200}")

}
开发者ID:antianlu,项目名称:goweb,代码行数:26,代码来源:goweb_api_responder_test.go


示例3: TestHTTP_WithOK

func TestHTTP_WithOK(t *testing.T) {

	httpResponder := new(GowebHTTPResponder)
	ctx := context_test.MakeTestContext()

	httpResponder.WithOK(ctx)

	assert.Equal(t, context_test.TestResponseWriter.WrittenHeaderInt, http.StatusOK)

}
开发者ID:rmulley,项目名称:goweb,代码行数:10,代码来源:goweb_http_responder_test.go


示例4: TestHTTP_WithStatus

func TestHTTP_WithStatus(t *testing.T) {

	httpResponder := new(GowebHTTPResponder)
	ctx := context_test.MakeTestContext()

	httpResponder.WithStatus(ctx, 500)

	assert.Equal(t, context_test.TestResponseWriter.StatusCode, 500)

}
开发者ID:antianlu,项目名称:goweb,代码行数:10,代码来源:goweb_http_responder_test.go


示例5: TestHTTP_WithTemporaryRedirect

func TestHTTP_WithTemporaryRedirect(t *testing.T) {

	httpResponder := new(GowebHTTPResponder)
	ctx := context_test.MakeTestContext()

	httpResponder.WithTemporaryRedirect(ctx, "people/123")

	assert.Equal(t, context_test.TestResponseWriter.WrittenHeaderInt, http.StatusTemporaryRedirect)
	assert.Equal(t, context_test.TestResponseWriter.Header()["Location"][0], "people/123")

}
开发者ID:rmulley,项目名称:goweb,代码行数:11,代码来源:goweb_http_responder_test.go


示例6: TestHTTP_WithStatusAndText

func TestHTTP_WithStatusAndText(t *testing.T) {

	httpResponder := new(GowebHTTPResponder)
	ctx := context_test.MakeTestContext()

	httpResponder.WithStatusText(ctx, 500)

	assert.Equal(t, context_test.TestResponseWriter.WrittenHeaderInt, 500)
	assert.Equal(t, context_test.TestResponseWriter.Output, http.StatusText(500))

}
开发者ID:rmulley,项目名称:goweb,代码行数:11,代码来源:goweb_http_responder_test.go


示例7: TestHTTP_With

func TestHTTP_With(t *testing.T) {

	http := new(GowebHTTPResponder)
	ctx := context_test.MakeTestContext()

	http.With(ctx, 200, []byte("Hello Goweb"))

	assert.Equal(t, context_test.TestResponseWriter.Output, "Hello Goweb")
	assert.Equal(t, context_test.TestResponseWriter.WrittenHeaderInt, 200)

}
开发者ID:rmulley,项目名称:goweb,代码行数:11,代码来源:goweb_http_responder_test.go


示例8: TestHTTP_WithPermanentRedirect

func TestHTTP_WithPermanentRedirect(t *testing.T) {

	httpResponder := new(GowebHTTPResponder)
	ctx := context_test.MakeTestContext()

	httpResponder.WithPermanentRedirect(ctx, "people/123")

	assert.Equal(t, context_test.TestResponseWriter.StatusCode, http.StatusMovedPermanently)
	assert.Equal(t, context_test.TestResponseWriter.Header()["Location"][0], "people/123")

}
开发者ID:antianlu,项目名称:goweb,代码行数:11,代码来源:goweb_http_responder_test.go


示例9: TestRespondWithPublicDataFacade

func TestRespondWithPublicDataFacade(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	data := new(dataObject)

	API.Respond(ctx, 200, data, nil)

	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"d\":{\"used-public-data\":true},\"s\":200}")

}
开发者ID:antianlu,项目名称:goweb,代码行数:13,代码来源:goweb_api_responder_test.go


示例10: TestRespond

func TestRespond(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	data := map[string]interface{}{"name": "Mat"}

	API.Respond(ctx, 200, data, nil)

	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"d\":{\"name\":\"Mat\"},\"s\":200}")

}
开发者ID:antianlu,项目名称:goweb,代码行数:13,代码来源:goweb_api_responder_test.go


示例11: TestAPI_RespondWithError

func TestAPI_RespondWithError(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	errObject := "error message"

	API.RespondWithError(ctx, 500, errObject)

	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"e\":[\"error message\"],\"s\":500}")

}
开发者ID:antianlu,项目名称:goweb,代码行数:13,代码来源:goweb_api_responder_test.go


示例12: TestAPI_WriteResponseObject_CodecOptions

func TestAPI_WriteResponseObject_CodecOptions(t *testing.T) {
	http := new(GowebHTTPResponder)
	codecService := new(codecsservices.WebCodecService)
	codecService.AddCodec(new(CodecOptionsTester))
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	test_option := "test"
	ctx.CodecOptions().Set("test_option", test_option)

	testData := "data"

	API.WriteResponseObject(ctx, 200, testData)

	assert.Equal(t, context_test.TestResponseWriter.Output, `{"data":"`+testData+`","test_option":"`+test_option+`"}`)
}
开发者ID:antianlu,项目名称:goweb,代码行数:15,代码来源:goweb_api_responder_test.go


示例13: TestRespondWithCustomFieldnames

func TestRespondWithCustomFieldnames(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	data := map[string]interface{}{"name": "Mat"}

	API.StandardFieldDataKey = "data"
	API.StandardFieldStatusKey = "status"

	API.Respond(ctx, 200, data, nil)

	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"data\":{\"name\":\"Mat\"},\"status\":200}")

}
开发者ID:antianlu,项目名称:goweb,代码行数:16,代码来源:goweb_api_responder_test.go


示例14: TestAPI_StandardResponseObjectTransformer

func TestAPI_StandardResponseObjectTransformer(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	data := map[string]interface{}{"name": "Mat"}

	API.SetStandardResponseObjectTransformer(func(ctx context.Context, sro interface{}) (interface{}, error) {

		return map[string]interface{}{
			"sro":       sro,
			"something": true,
		}, nil

	})

	API.RespondWithData(ctx, data)

	assert.Equal(t, context_test.TestResponseWriter.Output, "{\"something\":true,\"sro\":{\"d\":{\"name\":\"Mat\"},\"s\":200}}")

}
开发者ID:antianlu,项目名称:goweb,代码行数:22,代码来源:goweb_api_responder_test.go


示例15: TestWriteResponseObject_ContentNegotiation_FileExtension

// https://github.com/stretchr/goweb/issues/20
func TestWriteResponseObject_ContentNegotiation_FileExtension(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	ctx.HttpRequest().URL, _ = url.Parse("http://stretchr.org/something.msgpack")
	data := map[string]interface{}{"name": "Mat"}

	API.WriteResponseObject(ctx, 200, data)

	// get the expected output
	codec, codecErr := codecService.GetCodec("application/x-msgpack")
	if assert.NoError(t, codecErr) {

		expectedOutput, marshalErr := codec.Marshal(data, nil)
		if assert.NoError(t, marshalErr) {
			assert.Equal(t, []byte(context_test.TestResponseWriter.Output), expectedOutput)
		}

	}

}
开发者ID:antianlu,项目名称:goweb,代码行数:24,代码来源:goweb_api_responder_test.go


示例16: TestWriteResponseObject_ContentNegotiation_HasCallback

// https://github.com/stretchr/goweb/issues/20
func TestWriteResponseObject_ContentNegotiation_HasCallback(t *testing.T) {

	http := new(GowebHTTPResponder)
	codecService := codecsservices.NewWebCodecService()
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	ctx.HttpRequest().URL, _ = url.Parse("http://stretchr.org/something?callback=doSomething")
	data := map[string]interface{}{"name": "Mat"}

	API.WriteResponseObject(ctx, 200, data)

	// get the expected output
	codec, codecErr := codecService.GetCodec("text/javascript")
	if assert.NoError(t, codecErr) {

		expectedOutput, marshalErr := codec.Marshal(data, map[string]interface{}{"options.client.callback": "doSomething"})
		if assert.NoError(t, marshalErr) {
			assert.Equal(t, []byte(context_test.TestResponseWriter.Output), expectedOutput)
		}

	}

}
开发者ID:antianlu,项目名称:goweb,代码行数:24,代码来源:goweb_api_responder_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang test.MakeTestContextWithPath函数代码示例发布时间:2022-05-28
下一篇:
Golang test.TestHandler类代码示例发布时间: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