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

Golang testutils.NewHandler函数代码示例

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

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



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

示例1: TestFrontendUpdateBackend

func (s *VESuite) TestFrontendUpdateBackend(c *C) {
	server1 := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("1"))
	})
	defer server1.Close()

	server2 := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("2"))
	})
	defer server2.Close()

	// Create two different backends
	b1, srv1, url1 := "bk1", "srv1", server1.URL

	_, err := s.client.Set(s.path("backends", b1, "backend"), `{"Type": "http"}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b1, "servers", srv1), fmt.Sprintf(`{"URL": "%s"}`, url1), 0)
	c.Assert(err, IsNil)

	b2, srv2, url2 := "bk2", "srv2", server2.URL
	_, err = s.client.Set(s.path("backends", b2, "backend"), `{"Type": "http"}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b2, "servers", srv2), fmt.Sprintf(`{"URL": "%s"}`, url2), 0)
	c.Assert(err, IsNil)

	// Add frontend inititally pointing to the first backend
	fId := "fr1"
	_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)
	url := fmt.Sprintf("%s%s", s.serviceUrl, "/path")
	response, body, err := testutils.Get(url)
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusOK)
	c.Assert(string(body), Equals, "1")

	// Update the backend
	_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk2", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)
	response, body, err = testutils.Get(url)
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusOK)
	c.Assert(string(body), Equals, "2")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:49,代码来源:systest_test.go


示例2: TestPreservesTLS

// Make sure that stream handler preserves TLS settings
func (s *STSuite) TestPreservesTLS(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Write([]byte("ok"))
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	var t *tls.ConnectionState
	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		t = req.TLS
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)))
	c.Assert(err, IsNil)

	proxy := httptest.NewUnstartedServer(st)
	proxy.StartTLS()
	defer proxy.Close()

	re, _, err := testutils.Get(proxy.URL)
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusOK)

	c.Assert(t, NotNil)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:34,代码来源:stream_test.go


示例3: TestNoBody

func (s *STSuite) TestNoBody(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.WriteHeader(http.StatusOK)
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)))
	c.Assert(err, IsNil)

	proxy := httptest.NewServer(st)
	defer proxy.Close()

	re, _, err := testutils.Get(proxy.URL)
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusOK)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:27,代码来源:stream_test.go


示例4: TestCustomErrorHandler

func (s *STSuite) TestCustomErrorHandler(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello, this response is too large"))
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	errHandler := utils.ErrorHandlerFunc(func(w http.ResponseWriter, req *http.Request, err error) {
		w.WriteHeader(http.StatusTeapot)
		w.Write([]byte(http.StatusText(http.StatusTeapot)))
	})
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)), MaxResponseBodyBytes(4), ErrorHandler(errHandler))
	c.Assert(err, IsNil)

	proxy := httptest.NewServer(st)
	defer proxy.Close()

	re, _, err := testutils.Get(proxy.URL)
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusTeapot)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:31,代码来源:stream_test.go


示例5: TestChunkedEncodingLimitReached

func (s *STSuite) TestChunkedEncodingLimitReached(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello"))
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)), MemRequestBodyBytes(4), MaxRequestBodyBytes(8))
	c.Assert(err, IsNil)

	proxy := httptest.NewServer(st)
	defer proxy.Close()

	conn, err := net.Dial("tcp", testutils.ParseURI(proxy.URL).Host)
	c.Assert(err, IsNil)
	fmt.Fprintf(conn, "POST / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
	status, err := bufio.NewReader(conn).ReadString('\n')

	c.Assert(status, Equals, "HTTP/1.0 413 Request Entity Too Large\r\n")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:30,代码来源:stream_test.go


示例6: TestBackendUpdateOptions

func (s *ServerSuite) TestBackendUpdateOptions(c *C) {
	e := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		time.Sleep(10 * time.Millisecond)
		w.Write([]byte("slow server"))
	})
	defer e.Close()

	c.Assert(s.mux.Start(), IsNil)

	b := MakeBatch(Batch{Addr: "localhost:11300", Route: `Path("/")`, URL: e.URL})

	settings := b.B.HTTPSettings()
	settings.Timeouts = engine.HTTPBackendTimeouts{Read: "1ms"}
	b.B.Settings = settings

	c.Assert(s.mux.UpsertBackend(b.B), IsNil)
	c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
	c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
	c.Assert(s.mux.UpsertListener(b.L), IsNil)

	re, _, err := testutils.Get(MakeURL(b.L, "/"))
	c.Assert(err, IsNil)
	c.Assert(re, NotNil)
	c.Assert(re.StatusCode, Equals, http.StatusGatewayTimeout)

	settings.Timeouts = engine.HTTPBackendTimeouts{Read: "20ms"}
	b.B.Settings = settings

	c.Assert(s.mux.UpsertBackend(b.B), IsNil)

	c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "slow server")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:32,代码来源:mux_test.go


示例7: TestRequestLimitReached

func (s *STSuite) TestRequestLimitReached(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello"))
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)), MaxRequestBodyBytes(4))
	c.Assert(err, IsNil)

	proxy := httptest.NewServer(st)
	defer proxy.Close()

	re, _, err := testutils.Get(proxy.URL, testutils.Body("this request is too long"))
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusRequestEntityTooLarge)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:27,代码来源:stream_test.go


示例8: TestFileStreamingResponse

func (s *STSuite) TestFileStreamingResponse(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello, this response is too large to fit in memory"))
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)), MemResponseBodyBytes(4))
	c.Assert(err, IsNil)

	proxy := httptest.NewServer(st)
	defer proxy.Close()

	re, body, err := testutils.Get(proxy.URL)
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusOK)
	c.Assert(string(body), Equals, "hello, this response is too large to fit in memory")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:28,代码来源:stream_test.go


示例9: TestFrontendCRUD

// Set up a frontend hit this frontend with request and make sure everything worked fine
func (s *VESuite) TestFrontendCRUD(c *C) {
	called := false
	server := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		called = true
		w.Write([]byte("Hi, I'm fine, thanks!"))
	})
	defer server.Close()

	// Create a server
	b, srv, url := "bk1", "srv1", server.URL
	_, err := s.client.Set(s.path("backends", b, "backend"), `{"Type": "http"}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b, "servers", srv), fmt.Sprintf(`{"URL": "%s"}`, url), 0)
	c.Assert(err, IsNil)

	// Add frontend
	fId := "fr1"
	_, err = s.client.Set(s.path("frontends", fId, "frontend"),
		`{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)
	response, _, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusOK)
	c.Assert(called, Equals, true)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:29,代码来源:systest_test.go


示例10: TestServerHTTPS

func (s *ServerSuite) TestServerHTTPS(c *C) {
	var req *http.Request
	e := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		req = r
		w.Write([]byte("hi https"))
	})
	defer e.Close()

	b := MakeBatch(Batch{
		Addr:     "localhost:41000",
		Route:    `Path("/")`,
		URL:      e.URL,
		Protocol: engine.HTTPS,
		KeyPair:  &engine.KeyPair{Key: localhostKey, Cert: localhostCert},
	})

	c.Assert(s.mux.UpsertHost(b.H), IsNil)
	c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
	c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
	c.Assert(s.mux.UpsertListener(b.L), IsNil)

	c.Assert(s.mux.Start(), IsNil)

	c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "hi https")
	// Make sure that we see right proto
	c.Assert(req.Header.Get("X-Forwarded-Proto"), Equals, "https")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:27,代码来源:mux_test.go


示例11: TestHTTPSListenerCRUD

func (s *VESuite) TestHTTPSListenerCRUD(c *C) {
	called := false
	server := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		called = true
		w.Write([]byte("Hi, I'm fine, thanks!"))
	})
	defer server.Close()

	b, srv, url := "bk1", "srv1", server.URL
	_, err := s.client.Set(s.path("backends", b, "backend"), `{"Type": "http"}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b, "servers", srv), fmt.Sprintf(`{"URL": "%s"}`, url), 0)
	c.Assert(err, IsNil)

	// Add frontend
	fId := "fr1"
	_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	keyPair := NewTestKeyPair()

	bytes, err := secret.SealKeyPairToJSON(s.box, keyPair)
	c.Assert(err, IsNil)
	sealed := base64.StdEncoding.EncodeToString(bytes)
	host := "localhost"

	_, err = s.client.Set(s.path("hosts", host, "host"), fmt.Sprintf(`{"Name": "localhost", "Settings": {"KeyPair": "%v"}}`, sealed), 0)
	c.Assert(err, IsNil)

	// Add HTTPS listener
	l2 := "ls2"
	listener, err := engine.NewListener(l2, "https", "tcp", "localhost:32000", "", nil)
	c.Assert(err, IsNil)
	bytes, err = json.Marshal(listener)
	c.Assert(err, IsNil)
	s.client.Set(s.path("listeners", l2), string(bytes), 0)

	time.Sleep(time.Second)
	_, _, err = testutils.Get(fmt.Sprintf("%s%s", "https://localhost:32000", "/path"))
	c.Assert(err, IsNil)
	c.Assert(called, Equals, true)

	_, err = s.client.Delete(s.path("listeners", l2), true)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)

	_, _, err = testutils.Get(fmt.Sprintf("%s%s", "https://localhost:32000", "/path"))
	c.Assert(err, NotNil)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:51,代码来源:systest_test.go


示例12: TestServerUpdateHTTPS

func (s *ServerSuite) TestServerUpdateHTTPS(c *C) {
	var req *http.Request
	e := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		req = r
		w.Write([]byte("hi https"))
	})
	defer e.Close()

	b := MakeBatch(Batch{
		Addr:     "localhost:41000",
		Route:    `Path("/")`,
		URL:      e.URL,
		Protocol: engine.HTTPS,
		KeyPair:  &engine.KeyPair{Key: localhostKey, Cert: localhostCert},
	})

	b.L.Settings = &engine.HTTPSListenerSettings{TLS: engine.TLSSettings{MinVersion: "VersionTLS11"}}
	c.Assert(s.mux.UpsertHost(b.H), IsNil)
	c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
	c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
	c.Assert(s.mux.UpsertListener(b.L), IsNil)

	c.Assert(s.mux.Start(), IsNil)

	config := &tls.Config{
		InsecureSkipVerify: true,
		// We only support tls 10
		MinVersion: tls.VersionTLS10,
		MaxVersion: tls.VersionTLS10,
	}

	conn, err := tls.Dial("tcp", b.L.Address.Address, config)
	c.Assert(err, NotNil) // we got TLS error

	// Relax the version
	b.L.Settings = &engine.HTTPSListenerSettings{TLS: engine.TLSSettings{MinVersion: "VersionTLS10"}}
	c.Assert(s.mux.UpsertListener(b.L), IsNil)

	time.Sleep(20 * time.Millisecond)

	conn, err = tls.Dial("tcp", b.L.Address.Address, config)
	c.Assert(err, IsNil)

	fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
	status, err := bufio.NewReader(conn).ReadString('\n')

	c.Assert(status, Equals, "HTTP/1.0 200 OK\r\n")
	state := conn.ConnectionState()
	c.Assert(state.Version, DeepEquals, uint16(tls.VersionTLS10))
	conn.Close()
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:51,代码来源:mux_test.go


示例13: TestHTTPListenerCRUD

func (s *VESuite) TestHTTPListenerCRUD(c *C) {
	called := false
	server := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		called = true
		w.Write([]byte("Hi, I'm fine, thanks!"))
	})
	defer server.Close()

	b, srv, url := "bk1", "srv1", server.URL
	_, err := s.client.Set(s.path("backends", b, "backend"), `{"Type": "http"}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b, "servers", srv), fmt.Sprintf(`{"URL": "%s"}`, url), 0)
	c.Assert(err, IsNil)

	// Add frontend
	fId := "fr1"
	_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)
	response, _, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusOK)

	// Add HTTP listener
	l1 := "l1"
	listener, err := engine.NewListener(l1, "http", "tcp", "localhost:31000", "", nil)
	c.Assert(err, IsNil)
	bytes, err := json.Marshal(listener)
	c.Assert(err, IsNil)
	s.client.Set(s.path("listeners", l1), string(bytes), 0)

	time.Sleep(time.Second)
	_, _, err = testutils.Get(fmt.Sprintf("%s%s", "http://localhost:31000", "/path"))
	c.Assert(err, IsNil)
	c.Assert(called, Equals, true)

	_, err = s.client.Delete(s.path("listeners", l1), true)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)

	_, _, err = testutils.Get(fmt.Sprintf("%s%s", "http://localhost:31000", "/path"))
	c.Assert(err, NotNil)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:46,代码来源:systest_test.go


示例14: TestSuccess

func (s *RTSuite) TestSuccess(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello"))
	})
	defer srv.Close()

	lb, rt := new(c, `IsNetworkError() && Attempts() <= 2`)

	proxy := httptest.NewServer(rt)
	defer proxy.Close()

	lb.UpsertServer(testutils.ParseURI(srv.URL))

	re, body, err := testutils.Get(proxy.URL)
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusOK)
	c.Assert(string(body), Equals, "hello")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:18,代码来源:retry_test.go


示例15: TestRetryExceedAttempts

func (s *RTSuite) TestRetryExceedAttempts(c *C) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello"))
	})
	defer srv.Close()

	lb, rt := new(c, `IsNetworkError() && Attempts() <= 2`)

	proxy := httptest.NewServer(rt)
	defer proxy.Close()

	lb.UpsertServer(testutils.ParseURI("http://localhost:64321"))
	lb.UpsertServer(testutils.ParseURI("http://localhost:64322"))
	lb.UpsertServer(testutils.ParseURI("http://localhost:64323"))
	lb.UpsertServer(testutils.ParseURI(srv.URL))

	re, _, err := testutils.Get(proxy.URL)
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusBadGateway)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:20,代码来源:retry_test.go


示例16: TestMiddlewareOrder

func (s *ServerSuite) TestMiddlewareOrder(c *C) {
	var req *http.Request
	e := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		req = r
		w.Write([]byte("done"))
	})
	defer e.Close()

	c.Assert(s.mux.Start(), IsNil)

	b := MakeBatch(Batch{
		Addr:  "localhost:31000",
		Route: `Path("/")`,
		URL:   e.URL,
	})

	c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
	c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
	c.Assert(s.mux.UpsertListener(b.L), IsNil)

	a1 := engine.Middleware{
		Priority:   0,
		Type:       "appender",
		Id:         "a1",
		Middleware: &appender{append: "a1"},
	}

	a2 := engine.Middleware{
		Priority:   1,
		Type:       "appender",
		Id:         "a0",
		Middleware: &appender{append: "a2"},
	}

	c.Assert(s.mux.UpsertMiddleware(b.FK, a1), IsNil)
	c.Assert(s.mux.UpsertMiddleware(b.FK, a2), IsNil)

	c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "done")
	c.Assert(req.Header["X-Append"], DeepEquals, []string{"a1", "a2"})
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:40,代码来源:mux_test.go


示例17: TestBackendUpdateSettings

func (s *VESuite) TestBackendUpdateSettings(c *C) {
	server := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		time.Sleep(50 * time.Millisecond)
		w.Write([]byte("tc: update upstream options"))
	})
	defer server.Close()

	b, srv, url := "bk1", "srv1", server.URL
	_, err := s.client.Set(s.path("backends", b, "backend"), `{"Type": "http", "Settings": {"Timeouts": {"Read":"10ms"}}}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b, "servers", srv), fmt.Sprintf(`{"URL": "%s"}`, url), 0)
	c.Assert(err, IsNil)

	// Add frontend
	fId := "fr1"
	_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	// Wait for the changes to take effect
	time.Sleep(time.Second)

	// Make sure request times out
	response, _, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusGatewayTimeout)

	// Update backend timeout
	_, err = s.client.Set(s.path("backends", b, "backend"), `{"Type": "http", "Settings": {"Timeouts": {"Read":"100ms"}}}`, 0)
	c.Assert(err, IsNil)

	// Wait for the changes to take effect
	time.Sleep(time.Second)

	response, body, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusOK)
	c.Assert(string(body), Equals, "tc: update upstream options")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:39,代码来源:systest_test.go


示例18: TestServerNoBody

func (s *ServerSuite) TestServerNoBody(c *C) {
	e := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNotModified)
	})
	defer e.Close()

	c.Assert(s.mux.Start(), IsNil)

	b := MakeBatch(Batch{
		Addr:  "localhost:31000",
		Route: `Path("/")`,
		URL:   e.URL,
	})

	c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
	c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
	c.Assert(s.mux.UpsertListener(b.L), IsNil)

	re, _, err := testutils.Get(b.FrontendURL("/"))
	c.Assert(err, IsNil)
	c.Assert(re.StatusCode, Equals, http.StatusNotModified)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:22,代码来源:mux_test.go


示例19: TestChunkedEncodingSuccess

func (s *STSuite) TestChunkedEncodingSuccess(c *C) {
	var reqBody string
	var contentLength int64
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		body, err := ioutil.ReadAll(req.Body)
		c.Assert(err, IsNil)
		reqBody = string(body)
		contentLength = req.ContentLength
		w.Write([]byte("hello"))
	})
	defer srv.Close()

	// forwarder will proxy the request to whatever destination
	fwd, err := forward.New()
	c.Assert(err, IsNil)

	// this is our redirect to server
	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})

	// stream handler will forward requests to redirect
	st, err := New(rdr, Logger(utils.NewFileLogger(os.Stdout, utils.INFO)))
	c.Assert(err, IsNil)

	proxy := httptest.NewServer(st)
	defer proxy.Close()

	conn, err := net.Dial("tcp", testutils.ParseURI(proxy.URL).Host)
	c.Assert(err, IsNil)
	fmt.Fprintf(conn, "POST / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
	status, err := bufio.NewReader(conn).ReadString('\n')

	c.Assert(reqBody, Equals, "testtest1test2")
	c.Assert(status, Equals, "HTTP/1.0 200 OK\r\n")
	c.Assert(contentLength, Equals, int64(len(reqBody)))
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:38,代码来源:stream_test.go


示例20: TestFrontendUpdateLimits

func (s *VESuite) TestFrontendUpdateLimits(c *C) {
	var headers http.Header
	server := testutils.NewHandler(func(w http.ResponseWriter, r *http.Request) {
		headers = r.Header
		w.Write([]byte("Hello, I'm totally fine"))
	})
	defer server.Close()

	b, srv, url := "bk1", "srv1", server.URL
	_, err := s.client.Set(s.path("backends", b, "backend"), `{"Type": "http"}`, 0)
	c.Assert(err, IsNil)

	_, err = s.client.Set(s.path("backends", b, "servers", srv), fmt.Sprintf(`{"URL": "%s"}`, url), 0)
	c.Assert(err, IsNil)

	// Add frontend
	fId := "fr1"
	_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
	c.Assert(err, IsNil)

	time.Sleep(time.Second)
	response, _, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
	c.Assert(err, IsNil)

	c.Assert(response.StatusCode, Equals, http.StatusOK)
	c.Assert(response.Header.Get("X-Forwarded-For"), Not(Equals), "hello")

	_, err = s.client.Set(
		s.path("frontends", fId, "frontend"),
		`{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")", "Settings": {"Limits": {"MaxMemBodyBytes":2, "MaxBodyBytes":4}}}`, 0)
	c.Assert(err, IsNil)
	time.Sleep(time.Second)

	response, _, err = testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"), testutils.Body("This is longer than allowed 4 bytes"))
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, http.StatusRequestEntityTooLarge)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:37,代码来源:systest_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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