コード例 #1
0
ファイル: reverse_proxy_test.go プロジェクト: conductant/gohm
func (suite *TestSuiteReverseProxy) TestReverseProxy(c *C) {
	suite.lock.Lock()
	defer suite.lock.Unlock()

	suite.backendInvokes = 0
	suite.proxyInvokes = 0

	testutil.Get(c, "http://localhost:7712/:7891/test/get",
		func(resp *http.Response, body []byte) {
			c.Assert(resp.StatusCode, Equals, http.StatusOK)
		})
	c.Assert(suite.proxyInvokes, Equals, suite.backendInvokes)

	testutil.Get(c, "http://localhost:7712/127.0.0.1:7891/test/get",
		func(resp *http.Response, body []byte) {
			c.Assert(resp.StatusCode, Equals, http.StatusOK)
		})
	c.Assert(suite.proxyInvokes, Equals, suite.backendInvokes)

	testutil.Get(c, "http://localhost:7712/127.0.0.1:7891/test/bad/not/exist",
		func(resp *http.Response, body []byte) {
			c.Assert(resp.StatusCode, Equals, http.StatusNotFound)
		})
	c.Assert(suite.proxyInvokes, Equals, suite.backendInvokes+1)
}
コード例 #2
0
ファイル: server_test.go プロジェクト: conductant/gohm
func (suite *TestSuiteServer) TestNoAuthToken(c *C) {
	testutil.Get(c, "http://localhost:7890/simple-get",
		func(resp *http.Response, body []byte) {
			c.Assert(resp.StatusCode, Equals, http.StatusOK)
			c.Assert(body, DeepEquals, []byte("ok"))
		})
	testutil.Get(c, "http://localhost:7890/anon-get",
		func(resp *http.Response, body []byte) {
			c.Assert(resp.StatusCode, Equals, http.StatusOK)
			c.Assert(body, DeepEquals, []byte("ok"))
		})
	testutil.Get(c, "http://localhost:7890/api-from-context",
		func(resp *http.Response, body []byte) {
			c.Assert(resp.StatusCode, Equals, http.StatusUnauthorized)
		})
}