MCPcopy
hub / github.com/vulcand/vulcand / TestMiddlewareUpdate

Method TestMiddlewareUpdate

proxy/mux/mux_test.go:558–592  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

556}
557
558func (s *ServerSuite) TestMiddlewareUpdate(c *C) {
559 e := testutils.NewResponder("Hi, I'm endpoint 1")
560 defer e.Close()
561
562 b := MakeBatch(Batch{
563 Addr: "localhost:31000",
564 Route: `Path("/")`,
565 URL: e.URL,
566 })
567 c.Assert(s.mux.Init(b.Snapshot()), IsNil)
568 c.Assert(s.mux.Start(), IsNil)
569
570 // 1 request per second
571 rl := MakeRateLimit(UID("rl"), 1, "client.ip", 1, 1)
572
573 _, err := rl.Middleware.NewHandler(nil)
574 c.Assert(err, IsNil)
575
576 c.Assert(s.mux.UpsertMiddleware(b.FK, rl), IsNil)
577
578 c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
579 re, _, err := testutils.Get(MakeURL(b.L, "/"))
580 c.Assert(err, IsNil)
581 c.Assert(re.StatusCode, Equals, 429) // too many requests
582
583 // 100 requests per second
584 rl = MakeRateLimit(rl.Id, 100, "client.ip", 100, 1)
585
586 c.Assert(s.mux.UpsertMiddleware(b.FK, rl), IsNil)
587
588 for i := 0; i < 3; i++ {
589 c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
590 c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
591 }
592}
593
594func (s *ServerSuite) TestFrontendOptionsCRUD(c *C) {
595 e := testutils.NewResponder("Hi, I'm endpoint 1")

Callers

nothing calls this directly

Calls 13

MakeBatchFunction · 0.85
MakeRateLimitFunction · 0.85
UIDFunction · 0.85
MakeURLFunction · 0.85
FrontendURLMethod · 0.80
GETResponseFunction · 0.70
CloseMethod · 0.65
InitMethod · 0.65
StartMethod · 0.65
NewHandlerMethod · 0.65
UpsertMiddlewareMethod · 0.65
SnapshotMethod · 0.45

Tested by

no test coverage detected