func (s *BackendSuite) TestHostsFromJson(c *C) {
	h, err := NewHost("localhost")
	c.Assert(err, IsNil)

	up, err := NewUpstream("up1")
	c.Assert(err, IsNil)

	e, err := NewEndpoint("u1", "e1", "http://localhost")
	c.Assert(err, IsNil)

	l, err := NewLocation("localhost", "loc1", "/path", "up1")
	c.Assert(err, IsNil)

	cl, err := connlimit.NewConnLimit(10, "client.ip")
	c.Assert(err, IsNil)

	i := &MiddlewareInstance{Id: "c1", Type: "connlimit", Middleware: cl}

	up.Endpoints = []*Endpoint{e}
	l.Upstream = up
	l.Middlewares = []*MiddlewareInstance{i}
	h.Locations = []*Location{l}
	hosts := []*Host{h}

	bytes, err := json.Marshal(map[string]interface{}{"Hosts": hosts})

	out, err := HostsFromJson(bytes, registry.GetRegistry().GetSpec)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)

	c.Assert(out, DeepEquals, hosts)
}
Exemple #2
0
func (s *ApiSuite) makeConnLimit(id string, connections int64, variable string, priority int, loc *Location) *MiddlewareInstance {
	rl, err := connlimit.NewConnLimit(connections, variable)
	if err != nil {
		panic(err)
	}
	return &MiddlewareInstance{
		Type:       "connlimit",
		Id:         id,
		Middleware: rl,
	}
}
Exemple #3
0
func (s *ApiSuite) makeConnLimit(id string, connections int64, variable string, priority int, f *engine.Frontend) engine.Middleware {
	cl, err := connlimit.NewConnLimit(connections, variable)
	if err != nil {
		panic(err)
	}
	return engine.Middleware{
		Type:       "connlimit",
		Id:         id,
		Middleware: cl,
	}
}
Exemple #4
0
func (s *EngineSuite) makeConnLimit(id, variable string, conns int64) engine.Middleware {
	cl, err := connlimit.NewConnLimit(conns, variable)
	if err != nil {
		panic(err)
	}
	return engine.Middleware{
		Id:         id,
		Type:       "connlimit",
		Priority:   1,
		Middleware: cl,
	}
}
Exemple #5
0
func (s *BackendSuite) MiddlewareFromJSON(c *C) {
	cl, err := connlimit.NewConnLimit(10, "client.ip")
	c.Assert(err, IsNil)

	m := &Middleware{Id: "c1", Type: "connlimit", Middleware: cl}

	bytes, err := json.Marshal(m)
	c.Assert(err, IsNil)

	out, err := MiddlewareFromJSON(bytes, plugin.NewRegistry().GetSpec)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)
	c.Assert(out, DeepEquals, m)
}