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

Golang test_util.NewRequest函数代码示例

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

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



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

示例1: shouldEcho

func shouldEcho(input string, expected string) {
	ln := registerHandler(r, "encoding", func(x *test_util.HttpConn) {
		x.CheckLine("GET " + expected + " HTTP/1.1")
		resp := test_util.NewResponse(http.StatusOK)
		x.WriteResponse(resp)
		x.Close()
	})
	defer ln.Close()

	x := dialProxy(proxyServer)

	req := test_util.NewRequest("GET", "encoding", input, nil)
	x.WriteRequest(req)
	resp, _ := x.ReadResponse()

	Expect(resp.StatusCode).To(Equal(http.StatusOK))
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:17,代码来源:proxy_suite_test.go


示例2:

				AccessLogger:        fakeAccessLogger,
				SecureCookies:       conf.SecureCookies,
				TLSConfig:           tlsConfig,
				RouteServiceEnabled: conf.RouteServiceEnabled,
				RouteServiceTimeout: conf.RouteServiceTimeout,
				Crypto:              crypto,
				CryptoPrev:          cryptoPrev,
			})

			r.Register(route.Uri("some-app"), &route.Endpoint{})
		})

		Context("Log response time", func() {
			It("logs response time for HTTP connections", func() {
				body := []byte("some body")
				req := test_util.NewRequest("GET", "some-app", "/", bytes.NewReader(body))
				resp := httptest.NewRecorder()

				proxyObj.ServeHTTP(resp, req)
				Expect(fakeAccessLogger.LogCallCount()).To(Equal(1))
				Expect(fakeAccessLogger.LogArgsForCall(0).FinishedAt).NotTo(Equal(time.Time{}))
			})

			It("logs response time for TCP connections", func() {
				req := test_util.NewRequest("UPGRADE", "some-app", "/", nil)
				req.Header.Set("Upgrade", "tcp")
				req.Header.Set("Connection", "upgrade")
				resp := httptest.NewRecorder()

				proxyObj.ServeHTTP(resp, req)
				Expect(fakeAccessLogger.LogCallCount()).To(Equal(1))
开发者ID:idouba,项目名称:gorouter,代码行数:31,代码来源:proxy_unit_test.go


示例3:

			Value:   "xxx",
			MaxAge:  1,
			Expires: time.Now(),
		}
	})

	Context("context paths", func() {
		Context("when two requests have the same context paths", func() {
			It("responds with the same instance id", func() {
				ln := registerHandlerWithInstanceId(r, "app.com/path1", "", responseWithJSessionID, "instance-id-1")
				defer ln.Close()
				ln2 := registerHandlerWithInstanceId(r, "app.com/path2/context/path", "", responseWithJSessionID, "instance-id-2")
				defer ln2.Close()

				conn := dialProxy(proxyServer)
				req := test_util.NewRequest("GET", "app.com", "/path1/some/sub/path/index.html", nil)
				conn.WriteRequest(req)

				Eventually(done).Should(Receive())

				resp, _ := conn.ReadResponse()
				cookie := getCookie(proxy.VcapCookieId, resp.Cookies())
				Expect(cookie).ToNot(BeNil())
				Expect(cookie.Path).To(Equal("/path1"))
				Expect(cookie.Value).To(Equal("instance-id-1"))

				req2 := test_util.NewRequest("GET", "app.com", "/path1/other/sub/path/index.html", nil)
				conn.WriteRequest(req2)

				Eventually(done).Should(Receive())
开发者ID:idouba,项目名称:gorouter,代码行数:30,代码来源:session_affinity_test.go


示例4:

			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer lnWithoutSlash.Close()

		lnWithSlash := registerHandler(r, "test/another-path/your_path/", func(conn *test_util.HttpConn) {
			conn.CheckLine("GET /another-path/your_path HTTP/1.1")

			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer lnWithSlash.Close()

		conn := dialProxy(proxyServer)
		y := dialProxy(proxyServer)

		req := test_util.NewRequest("GET", "test", "/my%20path/your_path/", nil)
		conn.WriteRequest(req)

		resp, _ := conn.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))

		req = test_util.NewRequest("GET", "test", "/another-path/your_path", nil)
		y.WriteRequest(req)

		resp, _ = y.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
	})

	It("Content-type is not set by proxy", func() {
		ln := registerHandler(r, "content-test", func(x *test_util.HttpConn) {
			_, err := http.ReadRequest(x.Reader)
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:30,代码来源:proxy_test.go


示例5:

		})

		app.Listen()
		go app.RegisterRepeatedly(1 * time.Second)

		Eventually(func() bool {
			return appRegistered(registry, app)
		}).Should(BeTrue())

		conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", config.Ip, config.Port))
		Expect(err).NotTo(HaveOccurred())
		defer conn.Close()

		httpConn := test_util.NewHttpConn(conn)

		req := test_util.NewRequest("GET", "foo.vcap.me", "/", nil)
		req.Header.Add(router_http.VcapRequestIdHeader, "A-BOGUS-REQUEST-ID")

		httpConn.WriteRequest(req)

		var answer string
		Eventually(done).Should(Receive(&answer))
		Expect(answer).ToNot(Equal("A-BOGUS-REQUEST-ID"))
		Expect(answer).To(MatchRegexp(uuid_regex))
		Expect(logger).To(gbytes.Say("vcap-request-id-header-set"))

		resp, _ := httpConn.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
	})

	It("handles a /routes request", func() {
开发者ID:rakutentech,项目名称:gorouter,代码行数:31,代码来源:router_test.go


示例6:

			endpointIterator  *routefakes.FakeEndpointIterator
			transport         *proxyfakes.FakeRoundTripper
			handler           proxy.RequestHandler
			logger            lager.Logger
			req               *http.Request
			resp              *proxyfakes.FakeProxyResponseWriter
			dialError         = &net.OpError{
				Err: errors.New("error"),
				Op:  "dial",
			}
			after proxy.AfterRoundTrip
		)

		BeforeEach(func() {
			endpointIterator = &routefakes.FakeEndpointIterator{}
			req = test_util.NewRequest("GET", "myapp.com", "/", nil)
			req.URL.Scheme = "http"
			resp = &proxyfakes.FakeProxyResponseWriter{}
			nullVarz := nullVarz{}
			nullAccessRecord := &access_log.AccessLogRecord{}

			logger = lagertest.NewTestLogger("test")
			handler = proxy.NewRequestHandler(req, resp, nullVarz, nullAccessRecord, logger)
			transport = &proxyfakes.FakeRoundTripper{}

			after = func(rsp *http.Response, endpoint *route.Endpoint, err error) {
				Expect(endpoint.Tags).ShouldNot(BeNil())
			}

		})
开发者ID:shashankmjain,项目名称:gorouter,代码行数:30,代码来源:proxy_round_tripper_test.go


示例7:

			conf.RouteServiceEnabled = false
			conf.SSLSkipValidation = true
			routeServiceHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				Fail("Should not get here into Route Service")
			})
		})

		It("return 502 Bad Gateway", func() {
			ln := registerHandlerWithRouteService(r, "my_host.com", "https://"+routeServiceListener.Addr().String(), func(conn *test_util.HttpConn) {
				Fail("Should not get here into the app")
			})
			defer ln.Close()

			conn := dialProxy(proxyServer)

			req := test_util.NewRequest("GET", "my_host.com", "/", nil)

			conn.WriteRequest(req)

			res, body := conn.ReadResponse()
			Expect(res.StatusCode).To(Equal(http.StatusBadGateway))
			Expect(body).To(ContainSubstring("Support for route services is disabled."))
		})
	})

	Context("with SSLSkipValidation enabled", func() {
		BeforeEach(func() {
			conf.SSLSkipValidation = true
		})

		Context("when a request does not have a valid Route service signature header", func() {
开发者ID:idouba,项目名称:gorouter,代码行数:31,代码来源:route_service_test.go


示例8:

	})

	AfterEach(func() {
		crypto = nil
		cryptoPrev = nil
		config = nil
	})

	Describe("SetupRouteServiceRequest", func() {
		var (
			request *http.Request
			rsArgs  route_service.RouteServiceArgs
		)

		BeforeEach(func() {
			request = test_util.NewRequest("GET", "test.com", "/path/", nil)
			str := "https://example-route-service.com"
			parsed, err := url.Parse(str)
			Expect(err).NotTo(HaveOccurred())
			rsArgs = route_service.RouteServiceArgs{
				UrlString:       str,
				ParsedUrl:       parsed,
				Signature:       "signature",
				Metadata:        "metadata",
				ForwardedUrlRaw: "http://test.com/path/",
			}
		})

		It("sets the signature and metadata headers", func() {
			Expect(request.Header.Get(route_service.RouteServiceSignature)).To(Equal(""))
			Expect(request.Header.Get(route_service.RouteServiceMetadata)).To(Equal(""))
开发者ID:jungle0755,项目名称:gorouter,代码行数:31,代码来源:route_service_config_test.go


示例9:

			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer lnWithoutSlash.Close()

		lnWithSlash := registerHandler(r, "test/another-path/your_path/", func(conn *test_util.HttpConn) {
			conn.CheckLine("GET /another-path/your_path HTTP/1.1")

			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer lnWithSlash.Close()

		conn := dialProxy(proxyServer)
		y := dialProxy(proxyServer)

		req := test_util.NewRequest("GET", "test", "/my%20path/your_path/", nil)
		conn.WriteRequest(req)

		resp, _ := conn.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))

		req = test_util.NewRequest("GET", "test", "/another-path/your_path", nil)
		y.WriteRequest(req)

		resp, _ = y.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
	})

	It("responds to http/1.0 with path/path", func() {
		ln := registerHandler(r, "test/my%20path/your_path", func(conn *test_util.HttpConn) {
			conn.CheckLine("GET /my%20path/your_path HTTP/1.1")
开发者ID:jungle0755,项目名称:gorouter,代码行数:30,代码来源:proxy_test.go


示例10:

		It("websockets do not terminate", func() {
			app := test.NewWebSocketApp(
				[]route.Uri{"ws-app.vcap.me"},
				config.Port,
				mbusClient,
				1*time.Second,
			)
			app.Listen()

			conn, err := net.Dial("tcp", fmt.Sprintf("ws-app.vcap.me:%d", config.Port))
			Ω(err).NotTo(HaveOccurred())

			x := test_util.NewHttpConn(conn)

			req := test_util.NewRequest("GET", "/chat", nil)
			req.Host = "ws-app.vcap.me"
			req.Header.Set("Upgrade", "websocket")
			req.Header.Set("Connection", "upgrade")

			x.WriteRequest(req)

			resp, _ := x.ReadResponse()
			Ω(resp.StatusCode).To(Equal(http.StatusSwitchingProtocols))

			x.WriteLine("hello from client")
			x.CheckLine("hello from server")

			x.Close()
		})
	})
开发者ID:trainchou,项目名称:gorouter,代码行数:30,代码来源:router_test.go


示例11:

		jSessionIdCookie = &http.Cookie{
			Name:    proxy.StickyCookieKey,
			Value:   "xxx",
			MaxAge:  1,
			Expires: time.Now(),
		}
	})

	Context("first request", func() {
		Context("when the response does not contain a JESSIONID cookie", func() {
			It("does not respond with a VCAP_ID cookie", func() {
				ln := registerHandlerWithInstanceId(r, "app", responseNoCookies, "my-id")
				defer ln.Close()

				x := dialProxy(proxyServer)
				req := test_util.NewRequest("GET", "/", nil)
				req.Host = "app"
				x.WriteRequest(req)

				Eventually(done).Should(Receive())

				resp, _ := x.ReadResponse()
				Ω(getCookie(proxy.VcapCookieId, resp.Cookies())).Should(BeNil())
			})
		})

		Context("when the response contains a JESSIONID cookie", func() {
			It("responds with a VCAP_ID cookie scoped to the session", func() {
				ln := registerHandlerWithInstanceId(r, "app", responseWithJSessionID, "my-id")
				defer ln.Close()
开发者ID:trainchou,项目名称:gorouter,代码行数:30,代码来源:session_affinity_test.go


示例12:

			Ω(body).Should(Equal("ABCD"))

			rsp := test_util.NewResponse(200)
			out := &bytes.Buffer{}
			out.WriteString("DEFG")
			rsp.Body = ioutil.NopCloser(out)
			x.WriteResponse(rsp)
		})
		defer ln.Close()

		x := dialProxy(proxyServer)

		body := &bytes.Buffer{}
		body.WriteString("ABCD")
		req := test_util.NewRequest("POST", "/", ioutil.NopCloser(body))
		req.Host = "test"
		x.WriteRequest(req)

		x.CheckLine("HTTP/1.1 200 OK")

		var payload []byte
		Eventually(func() int {
			accessLogFile.Read(&payload)
			return len(payload)
		}).ShouldNot(BeZero())

		//make sure the record includes all the data
		//since the building of the log record happens throughout the life of the request
		Ω(strings.HasPrefix(string(payload), "test - [")).Should(BeTrue())
		Ω(string(payload)).To(ContainSubstring(`"POST / HTTP/1.1" 200 4 4 "-"`))
开发者ID:trainchou,项目名称:gorouter,代码行数:30,代码来源:proxy_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang test_util.NewResponse函数代码示例发布时间:2022-05-23
下一篇:
Golang test_util.NewHttpConn函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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