當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gspec.Request函數代碼示例

本文整理匯總了Golang中github.com/viki-org/gspec.Request函數的典型用法代碼示例。如果您正苦於以下問題:Golang Request函數的具體用法?Golang Request怎麽用?Golang Request使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Request函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/viki-org/gspec.Request函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。