func (s *S) TestDeployRemoveContainersEvenWhenTheyreNotInTheAppsCollection(c *gocheck.C) { h := &tsrTesting.TestHandler{} gandalfServer := tsrTesting.StartGandalfTestServer(h) defer gandalfServer.Close() go s.stopContainers(3) err := newImage("tsuru/python", s.server.URL()) c.Assert(err, gocheck.IsNil) cont1, err := s.newContainer(nil) c.Assert(err, gocheck.IsNil) _, err = s.newContainer(nil) c.Assert(err, gocheck.IsNil) defer rtesting.FakeRouter.RemoveBackend(cont1.AppName) var p dockerProvisioner a := app.App{ Name: "otherapp", Platform: "python", Units: []app.Unit{{Name: "i-0800", State: "started"}}, } conn, err := db.Conn() defer conn.Close() err = conn.Apps().Insert(a) c.Assert(err, gocheck.IsNil) defer conn.Apps().Remove(bson.M{"name": a.Name}) p.Provision(&a) defer p.Destroy(&a) fexec := &etesting.FakeExecutor{} setExecut(fexec) defer setExecut(nil) var w bytes.Buffer err = app.DeployApp(&a, "master", &w) c.Assert(err, gocheck.IsNil) time.Sleep(1e9) defer p.Destroy(&a) q, err := getQueue() c.Assert(err, gocheck.IsNil) for _, u := range a.ProvisionedUnits() { message, err := q.Get(1e6) c.Assert(err, gocheck.IsNil) defer message.Delete() c.Assert(err, gocheck.IsNil) c.Assert(message.Action, gocheck.Equals, app.BindService) c.Assert(message.Args[0], gocheck.Equals, a.GetName()) c.Assert(message.Args[1], gocheck.Equals, u.GetName()) } coll := collection() defer coll.Close() n, err := coll.Find(bson.M{"appname": cont1.AppName}).Count() c.Assert(err, gocheck.IsNil) c.Assert(n, gocheck.Equals, 2) }
func (s *S) TestDeploy(c *gocheck.C) { h := &tsrTesting.TestHandler{} gandalfServer := tsrTesting.StartGandalfTestServer(h) defer gandalfServer.Close() go s.stopContainers(1) err := newImage("tsuru/python", s.server.URL()) c.Assert(err, gocheck.IsNil) fexec := &etesting.FakeExecutor{} setExecut(fexec) defer setExecut(nil) p := dockerProvisioner{} app.Provisioner = &p a := app.App{ Name: "otherapp", Platform: "python", Units: []app.Unit{{Name: "i-0800", State: "started"}}, } conn, err := db.Conn() defer conn.Close() err = conn.Apps().Insert(a) c.Assert(err, gocheck.IsNil) defer conn.Apps().Remove(bson.M{"name": a.Name}) p.Provision(&a) defer p.Destroy(&a) w := writer{b: make([]byte, 2048)} err = app.DeployApp(&a, "master", &w) c.Assert(err, gocheck.IsNil) w.b = nil defer p.Destroy(&a) time.Sleep(6e9) q, err := getQueue() for _, u := range a.ProvisionedUnits() { message, err := q.Get(1e6) c.Assert(err, gocheck.IsNil) defer message.Delete() c.Assert(err, gocheck.IsNil) c.Assert(message.Action, gocheck.Equals, app.BindService) c.Assert(message.Args[0], gocheck.Equals, a.GetName()) c.Assert(message.Args[1], gocheck.Equals, u.GetName()) } }