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

Golang gspec.Request函数代码示例

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

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



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

示例1: TestCreatesARequestWithTheCorrectHostAndUrl

func TestCreatesARequestWithTheCorrectHostAndUrl(t *testing.T) {
	spec := gspec.New(t)
	context := core.NewContext(gspec.Request().Url("/test.json").Req)
	req := newRequest(context, &core.Config{Upstream: "s3.viki.com"})
	spec.Expect(req.Host).ToEqual("s3.viki.com")
	spec.Expect(req.URL.Path).ToEqual("/test.json")
}
开发者ID:karlseguin,项目名称:seedcdn,代码行数:7,代码来源:proxy_test.go


示例2: TestCreatesARequestWithTheCorrectRange

func TestCreatesARequestWithTheCorrectRange(t *testing.T) {
	spec := gspec.New(t)
	context := core.NewContext(gspec.Request().Url("somefile.mp4").Req)
	context.Chunk = 3
	req := newRequest(context, &core.Config{RangedExtensions: map[string]bool{".mp4": true}})
	spec.Expect(req.Header.Get("range")).ToEqual("bytes=6291456-8388607")
}
开发者ID:karlseguin,项目名称:seedcdn,代码行数:7,代码来源:proxy_test.go


示例3: TestIgnoresTheRangeForNonRangeTypes

func TestIgnoresTheRangeForNonRangeTypes(t *testing.T) {
	spec := gspec.New(t)
	context := core.NewContext(gspec.Request().Url("somefile.mp4").Req)
	context.Chunk = 3
	req := newRequest(context, new(core.Config))
	spec.Expect(req.Header.Get("range")).ToEqual("")
}
开发者ID:karlseguin,项目名称:seedcdn,代码行数:7,代码来源:proxy_test.go


示例4: TestExecutesAListAction

func TestExecutesAListAction(t *testing.T) {
	f := func(context interface{}) Response { return Json(`{"spice":"mustflow"}`).Response }
	req := gspec.Request().Url("/v4/sessions.json").Req
	res := httptest.NewRecorder()
	router := newRouter(Configure().Route(R("LIST", "v4", "sessions", f)))
	router.ServeHTTP(res, req)
	assertResponse(t, res, 200, `{"spice":"mustflow"}`)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:8,代码来源:router_test.go


示例5: TestExecutesAnActionRegardlessOfCasing

func TestExecutesAnActionRegardlessOfCasing(t *testing.T) {
	f := func(context interface{}) Response { return Json(`{"name":"duncan"}`).Response }
	req := gspec.Request().Url("/v2/GHOLAS/123g.json").Req
	res := httptest.NewRecorder()
	router := newRouter(Configure().Route(R("GET", "v2", "gholas", f)))
	router.ServeHTTP(res, req)
	assertResponse(t, res, 200, `{"name":"duncan"}`)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:8,代码来源:router_test.go


示例6: TestLogsStatisticsToRedis

func TestLogsStatisticsToRedis(t *testing.T) {
	conn := pool.Get()
	defer cleanup(conn)
	spec := gspec.New(t)
	Run(core.NewContext(gspec.Request().Url("/something/funny.txt").Req), nil, core.NoopMiddleware)
	time.Sleep(time.Second * 1)
	spec.Expect(redis.Int(conn.Do("zscore", "hits", "/something/funny.txt"))).ToEqual(1)
}
开发者ID:karlseguin,项目名称:seedcdn,代码行数:8,代码来源:logs_test.go


示例7: TestHandlesANilResponse

func TestHandlesANilResponse(t *testing.T) {
	f := func(context interface{}) Response { return nil }
	c := Configure().Route(R("GET", "v1", "worms", f))
	req := gspec.Request().Url("/v1/worms/22w.json").Method("GET").Req
	res := httptest.NewRecorder()
	newRouter(c).ServeHTTP(res, req)
	assertResponse(t, res, 500, `{"error":"internal server error","code":500}`)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:8,代码来源:router_test.go


示例8: TestHandlesBodiesLargerThanAllowed

func TestHandlesBodiesLargerThanAllowed(t *testing.T) {
	f := func(context *TestContext) Response { return Json("").Response }
	c := Configure().Route(R("GET", "v1", "worms", f).BodyFactory(testBodyFactory)).ContextFactory(testContextFactory).Dispatcher(testDispatcher).BodyPool(3, 1)
	req := gspec.Request().Url("/v1/worms/22w.json").Method("GET").BodyString(`{"hello":"World"}`).Req
	res := httptest.NewRecorder()
	newRouter(c).ServeHTTP(res, req)
	assertResponse(t, res, 413, `{"error":"body too large","code":413}`)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:8,代码来源:router_test.go


示例9: TestExecutesAPutAction

func TestExecutesAPutAction(t *testing.T) {
	f := func(context interface{}) Response { return Json(`{"name":"shaihulud"}`).Response }
	req := gspec.Request().Url("/v1/worms/22w.json").Method("PUT").Req
	res := httptest.NewRecorder()
	router := newRouter(Configure().Route(R("PUT", "v1", "worms", f)))
	router.ServeHTTP(res, req)
	assertResponse(t, res, 200, `{"name":"shaihulud"}`)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:8,代码来源:router_test.go


示例10: TestNoIpPresent

func TestNoIpPresent(t *testing.T) {
	f := func(context *TestContext) Response {
		gspec.New(t).Expect(context.Ip).ToEqual("127.0.0.1")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json").Method("GET").Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:9,代码来源:context_test.go


示例11: TestLoadCountryFromIpWhenNoXGeoIpHeader

func TestLoadCountryFromIpWhenNoXGeoIpHeader(t *testing.T) {
	f := func(context *TestContext) Response {
		gspec.New(t).Expect(context.Country).ToEqual("cn")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Header("x-forwarded-for", "218.108.232.190").Url("/v1/worms/22w.json").Method("GET")
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req.Req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:9,代码来源:context_test.go


示例12: TestLoadIpFromXForwardedHeader

func TestLoadIpFromXForwardedHeader(t *testing.T) {
	f := func(context *TestContext) Response {
		gspec.New(t).Expect(context.Ip).ToEqual("12.12.12.12")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Header("x-forwarded-for", "12.12.12.12,13.13.13.13").Url("/v1/worms/22w.json").Method("GET")
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req.Req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:9,代码来源:context_test.go


示例13: TestParsesQueryStirngWithEmptyPairAtTheStart

func TestParsesQueryStirngWithEmptyPairAtTheStart(t *testing.T) {
	spec := gspec.New(t)
	f := func(context *TestContext) Response {
		spec.Expect(context.Query["app"]).ToEqual("100004a")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json?&app=100004a").Method("GET").Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:10,代码来源:router_test.go


示例14: TestHandlesMultipleQuestionMarksInQueryString

func TestHandlesMultipleQuestionMarksInQueryString(t *testing.T) {
	spec := gspec.New(t)
	f := func(context *TestContext) Response {
		spec.Expect(context.Query["app"]).ToEqual("100005a")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json?app=100002a?app=100005a").Method("GET").Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:10,代码来源:router_test.go


示例15: TestParsesAQueryStringWithAMissingValue2

func TestParsesAQueryStringWithAMissingValue2(t *testing.T) {
	spec := gspec.New(t)
	f := func(context *TestContext) Response {
		spec.Expect(context.Query["b"]).ToEqual("")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json?b=").Method("GET").Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:10,代码来源:router_test.go


示例16: TestStoresRawBody

func TestStoresRawBody(t *testing.T) {
	spec := gspec.New(t)
	f := func(context *TestContext) Response {
		spec.Expect(string(context.RawBody)).ToEqual(`{"hello":"World"}`)
		return Json("").Response
	}
	c := Configure().LoadRawBody().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json").Method("GET").BodyString(`{"hello":"World"}`).Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:10,代码来源:router_test.go


示例17: TestDefaulsTheBodyValueWhenNoBodyIsPresent

func TestDefaulsTheBodyValueWhenNoBodyIsPresent(t *testing.T) {
	spec := gspec.New(t)
	f := func(context *TestContext) Response {
		input := context.Body.(*TestBody)
		spec.Expect(input.Hello).ToEqual("")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f).BodyFactory(testBodyFactory)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json").Method("GET").Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:11,代码来源:router_test.go


示例18: TestDeletesTheFilesDirectory

func TestDeletesTheFilesDirectory(t *testing.T) {
	spec := gspec.New(t)
	dir := setupTempFolder(spec)
	defer cleanupTempFolder()

	res := httptest.NewRecorder()
	Run(core.NewContext(gspec.Request().Method("purge").Req), res, nil)
	spec.Expect(res.Code).ToEqual(200)
	_, err := os.Stat(dir)
	spec.Expect(err).ToNotBeNil()
}
开发者ID:karlseguin,项目名称:seedcdn,代码行数:11,代码来源:purge_test.go


示例19: TestParsesQueryString

func TestParsesQueryString(t *testing.T) {
	spec := gspec.New(t)
	f := func(context *TestContext) Response {
		spec.Expect(context.Query["app"]).ToEqual("6003")
		spec.Expect(context.Query["t"]).ToEqual("1 2")
		return Json("").Response
	}
	c := Configure().Route(R("GET", "v1", "worms", f)).ContextFactory(testContextFactory).Dispatcher(testDispatcher)
	req := gspec.Request().Url("/v1/worms/22w.json?APP=6003&t=1%202&").Req
	newRouter(c).ServeHTTP(httptest.NewRecorder(), req)
}
开发者ID:viki-org,项目名称:auwfg,代码行数:11,代码来源:router_test.go


示例20: TestOnlyAllowsWhitelistedIpsToPurge

func TestOnlyAllowsWhitelistedIpsToPurge(t *testing.T) {
	spec := gspec.New(t)
	dir := setupTempFolder(spec)
	defer cleanupTempFolder()

	res := httptest.NewRecorder()
	Run(core.NewContext(gspec.Request().Method("purge").RemoteAddr("23.33.24.55:4343").Req), res, nil)
	spec.Expect(res.Code).ToEqual(401)
	spec.Expect(res.Body.Len()).ToEqual(0)
	_, err := os.Stat(dir)
	spec.Expect(err).ToBeNil()
}
开发者ID:karlseguin,项目名称:seedcdn,代码行数:12,代码来源:purge_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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