本文整理汇总了Golang中github.com/cloudfoundry/gorouter/test.NewTestApp函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestApp函数的具体用法?Golang NewTestApp怎么用?Golang NewTestApp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTestApp函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestProxyPutRequest
func (s *RouterSuite) TestProxyPutRequest(c *C) {
app := test.NewTestApp([]route.Uri{"greet.vcap.me"}, s.Config.Port, s.mbusClient, nil)
var rr *http.Request
var msg string
app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) {
rr = r
b, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
msg = string(b)
})
app.Listen()
c.Assert(s.waitAppRegistered(app, time.Second*5), Equals, true)
url := app.Endpoint()
buf := bytes.NewBufferString("foobar")
r, err := http.NewRequest("PUT", url, buf)
c.Assert(err, IsNil)
resp, err := http.DefaultClient.Do(r)
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(rr, NotNil)
c.Assert(rr.Method, Equals, "PUT")
c.Assert(rr.Proto, Equals, "HTTP/1.1")
c.Assert(msg, Equals, "foobar")
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:32,代码来源:router_test.go
示例2: Test100ContinueRequest
func (s *RouterSuite) Test100ContinueRequest(c *C) {
app := test.NewTestApp([]route.Uri{"foo.vcap.me"}, s.Config.Port, s.mbusClient, nil)
rCh := make(chan *http.Request)
app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) {
_, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
}
rCh <- r
})
<-s.WaitUntilNatsIsUp()
app.Listen()
go app.RegisterRepeatedly(1 * time.Second)
c.Assert(s.waitAppRegistered(app, time.Second*5), Equals, true)
host := fmt.Sprintf("foo.vcap.me:%d", s.Config.Port)
conn, err := net.Dial("tcp", host)
c.Assert(err, IsNil)
defer conn.Close()
fmt.Fprintf(conn, "POST / HTTP/1.1\r\n"+
"Host: %s\r\n"+
"Connection: close\r\n"+
"Content-Length: 1\r\n"+
"Expect: 100-continue\r\n"+
"\r\n", host)
fmt.Fprintf(conn, "a")
buf := bufio.NewReader(conn)
line, err := buf.ReadString('\n')
c.Assert(err, IsNil)
c.Assert(strings.Contains(line, "100 Continue"), Equals, true)
rr := <-rCh
c.Assert(rr, NotNil)
c.Assert(rr.Header.Get("Expect"), Equals, "")
}
开发者ID:jackfengibm,项目名称:gorouter,代码行数:41,代码来源:router_test.go
示例3:
r.Run()
})
AfterEach(func() {
if natsRunner != nil {
natsRunner.Stop()
}
if router != nil {
router.Stop()
}
})
Context("Drain", func() {
It("waits until the last request completes", func() {
app := test.NewTestApp([]route.Uri{"drain.vcap.me"}, config.Port, mbusClient, nil)
blocker := make(chan bool)
resultCh := make(chan bool, 2)
app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) {
blocker <- true
_, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
Ω(err).ShouldNot(HaveOccurred())
<-blocker
w.WriteHeader(http.StatusNoContent)
})
app.Listen()
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:31,代码来源:router_drain_test.go
示例4:
config = createConfig(cfgFile, statusPort, proxyPort)
})
JustBeforeEach(func() {
gorouterSession = startGorouterSession(cfgFile)
})
It("waits for all requests to finish", func() {
mbusClient, err := newMessageBus(config)
Expect(err).ToNot(HaveOccurred())
requestMade := make(chan bool)
requestProcessing := make(chan bool)
responseRead := make(chan bool)
longApp := test.NewTestApp([]route.Uri{"longapp.vcap.me"}, proxyPort, mbusClient, nil, "")
longApp.AddHandler("/", func(w http.ResponseWriter, r *http.Request) {
requestMade <- true
<-requestProcessing
_, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
Expect(err).ToNot(HaveOccurred())
w.WriteHeader(http.StatusOK)
w.Write([]byte{'b'})
})
longApp.Listen()
routesUri := fmt.Sprintf("http://%s:%[email protected]%s:%d/routes", config.Status.User, config.Status.Pass, localIP, statusPort)
Eventually(func() bool {
return appRegistered(routesUri, longApp)
}).Should(BeTrue())
开发者ID:jungle0755,项目名称:gorouter,代码行数:31,代码来源:main_test.go
示例5:
}).Should(BeTrue())
}
sessionCookie, vcapCookie, port1 := getSessionAndAppPort("sticky.vcap.me", config.Port)
port2 := getAppPortWithSticky("sticky.vcap.me", config.Port, sessionCookie, vcapCookie)
Expect(port1).To(Equal(port2))
Expect(vcapCookie.Path).To(Equal("/"))
for _, app := range apps {
app.Unregister()
}
})
Context("Stop", func() {
It("no longer proxies http", func() {
app := test.NewTestApp([]route.Uri{"greet.vcap.me"}, config.Port, mbusClient, nil, "")
app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) {
_, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
Expect(err).ToNot(HaveOccurred())
w.WriteHeader(http.StatusNoContent)
})
app.Listen()
Eventually(func() bool {
return appRegistered(registry, app)
}).Should(BeTrue())
req, err := http.NewRequest("GET", app.Endpoint(), nil)
Expect(err).ToNot(HaveOccurred())
开发者ID:shashankmjain,项目名称:gorouter,代码行数:30,代码来源:router_test.go
注:本文中的github.com/cloudfoundry/gorouter/test.NewTestApp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论