示例#1
0
func MakeBackend() engine.Backend {
	b, err := engine.NewHTTPBackend(UID("backend"), engine.HTTPBackendSettings{})
	if err != nil {
		panic(err)
	}
	return *b
}
示例#2
0
func (s *ApiSuite) TestMiddlewareCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	f, err := engine.NewHTTPFrontend(s.ng.GetRegistry().GetRouter(), "f1", b.Id, `Path("/")`, engine.HTTPFrontendSettings{})
	c.Assert(err, IsNil)
	fk := engine.FrontendKey{Id: f.Id}

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	cl := s.makeConnLimit("c1", 10, "client.ip", 2, f)
	c.Assert(s.client.UpsertMiddleware(fk, cl, 0), IsNil)

	ms, err := s.client.GetMiddlewares(fk)
	c.Assert(err, IsNil)
	c.Assert(ms[0], DeepEquals, cl)

	cl = s.makeConnLimit("c1", 10, "client.ip", 3, f)
	c.Assert(s.client.UpsertMiddleware(fk, cl, 0), IsNil)

	mk := engine.MiddlewareKey{Id: cl.Id, FrontendKey: fk}
	v, err := s.client.GetMiddleware(mk)
	c.Assert(err, IsNil)
	c.Assert(v, DeepEquals, &cl)

	c.Assert(s.client.DeleteMiddleware(mk), IsNil)

	_, err = s.client.GetMiddleware(mk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})

}
示例#3
0
func (s *ApiSuite) TestFrontendCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	f, err := engine.NewHTTPFrontend(s.ng.GetRegistry().GetRouter(), "f1", b.Id, `Path("/")`, engine.HTTPFrontendSettings{})
	c.Assert(err, IsNil)
	fk := engine.FrontendKey{Id: f.Id}

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	fs, err := s.client.GetFrontends()
	c.Assert(err, IsNil)
	c.Assert(fs[0], DeepEquals, *f)

	out, err := s.client.GetFrontend(fk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, f)

	settings := f.HTTPSettings()
	settings.Hostname = `localhost`
	f.Settings = settings
	f.Route = `Path("/v2")`

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	c.Assert(s.client.DeleteFrontend(fk), IsNil)

	out, err = s.client.GetFrontend(fk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}
示例#4
0
func (s *ApiSuite) TestBackendCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	bs, _ := s.ng.GetBackends()
	c.Assert(len(bs), Equals, 1)
	c.Assert(bs[0], DeepEquals, *b)

	bs, err = s.client.GetBackends()
	c.Assert(bs, NotNil)
	c.Assert(err, IsNil)
	c.Assert(bs[0], DeepEquals, *b)

	bk := engine.BackendKey{Id: b.Id}
	out, err := s.client.GetBackend(bk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, b)

	settings := b.HTTPSettings()
	settings.Timeouts.Read = "1s"
	b.Settings = settings
	c.Assert(s.client.UpsertBackend(*b), IsNil)

	out, err = s.client.GetBackend(bk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, b)

	err = s.client.DeleteBackend(bk)
	c.Assert(err, IsNil)

	out, err = s.client.GetBackend(bk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}
示例#5
0
func (cmd *Command) upsertBackendAction(c *cli.Context) {
	settings, err := getBackendSettings(c)
	if err != nil {
		cmd.printError(err)
		return
	}
	b, err := engine.NewHTTPBackend(c.String("id"), settings)
	if err != nil {
		cmd.printError(err)
		return
	}
	cmd.printResult("%s upserted", b, cmd.client.UpsertBackend(*b))
}
示例#6
0
func (s *ApiSuite) TestServerCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	srv1 := engine.Server{Id: "srv1", URL: "http://localhost:5000"}
	srv2 := engine.Server{Id: "srv2", URL: "http://localhost:6000"}

	bk := engine.BackendKey{Id: b.Id}
	c.Assert(s.client.UpsertServer(bk, srv1, 0), IsNil)
	c.Assert(s.client.UpsertServer(bk, srv2, 0), IsNil)

	srvs, _ := s.ng.GetServers(bk)
	c.Assert(len(srvs), Equals, 2)
	c.Assert(srvs[0], DeepEquals, srv1)
	c.Assert(srvs[1], DeepEquals, srv2)

	srvs, err = s.client.GetServers(bk)
	c.Assert(srvs, NotNil)
	c.Assert(len(srvs), Equals, 2)
	c.Assert(srvs[0], DeepEquals, srv1)
	c.Assert(srvs[1], DeepEquals, srv2)

	sk := engine.ServerKey{Id: srv1.Id, BackendKey: bk}
	out, err := s.client.GetServer(sk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, &srv1)

	srv1.URL = "http://localhost:5001"
	c.Assert(s.client.UpsertServer(bk, srv1, 0), IsNil)

	out, err = s.client.GetServer(sk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, &srv1)

	err = s.client.DeleteServer(sk)
	c.Assert(err, IsNil)

	out, err = s.client.GetServer(sk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}