本文整理汇总了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;未经允许,请勿转载。 |
请发表评论