func (s *S) TestProvisionerProvision(c *gocheck.C) { config.Set("local:authorized-key-path", "somepath") rfs := &fstesting.RecordingFs{} fsystem = rfs defer func() { fsystem = nil }() f, _ := os.Open("testdata/dnsmasq.leases") data, err := ioutil.ReadAll(f) c.Assert(err, gocheck.IsNil) file, err := rfs.Create("/var/lib/misc/dnsmasq.leases") c.Assert(err, gocheck.IsNil) _, err = file.Write(data) c.Assert(err, gocheck.IsNil) tmpdir, err := commandmocker.Add("sudo", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) sshTempDir, err := commandmocker.Add("ssh", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(sshTempDir) scpTempDir, err := commandmocker.Add("scp", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(scpTempDir) var p LocalProvisioner app := testing.NewFakeApp("myapp", "python", 0) defer p.collection().Remove(bson.M{"name": "myapp"}) c.Assert(p.Provision(app), gocheck.IsNil) ok := make(chan bool, 1) go func() { for { coll := s.conn.Collection(s.collName) ct, err := coll.Find(bson.M{"name": "myapp", "status": provision.StatusStarted}).Count() if err != nil { c.Fatal(err) } if ct > 0 { ok <- true return } time.Sleep(1e3) } }() select { case <-ok: case <-time.After(10e9): c.Fatal("Timed out waiting for the container to be provisioned (10 seconds)") } c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) expected := "lxc-create -t ubuntu -n myapp -- -S somepath" expected += "lxc-start --daemon -n myapp" expected += "service nginx restart" c.Assert(commandmocker.Output(tmpdir), gocheck.Equals, expected) var unit provision.Unit err = s.conn.Collection(s.collName).Find(bson.M{"name": "myapp"}).One(&unit) c.Assert(err, gocheck.IsNil) c.Assert(unit.Ip, gocheck.Equals, "10.10.10.15") }
func (s *S) TestAddRoute(c *gocheck.C) { tmpdir, err := commandmocker.Add("sudo", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) config.Set("nginx:domain", "andrewzito.com") config.Set("nginx:routes-path", "testdata") rfs := &testing.RecordingFs{} fsystem = rfs defer func() { fsystem = nil }() var r NginxRouter err = r.AddRoute("name", "127.0.0.1") c.Assert(err, gocheck.IsNil) file, err := rfs.Open("testdata/name") c.Assert(err, gocheck.IsNil) data, err := ioutil.ReadAll(file) c.Assert(err, gocheck.IsNil) expected := `server { listen 80; server_name name.andrewzito.com; location / { proxy_pass http://127.0.0.1; } }` c.Assert(string(data), gocheck.Equals, expected) c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) expected = "service nginx restart" c.Assert(commandmocker.Output(tmpdir), gocheck.Equals, expected) }
func (s *ELBSuite) TestHandleMessagesAllPendingUnits(c *gocheck.C) { app := testing.NewFakeApp("2112", "python", 1) router, err := Router() c.Assert(err, gocheck.IsNil) err = router.AddBackend(app.GetName()) c.Assert(err, gocheck.IsNil) defer router.RemoveBackend(app.GetName()) tmpdir, err := commandmocker.Add("juju", collectOutputAllPending) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) msg := queue.Message{ Action: addUnitToLoadBalancer, Args: []string{"2112", "2112/0", "2112/1"}, } handle(&msg) resp, err := s.client.DescribeLoadBalancers(app.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) instances := resp.LoadBalancerDescriptions[0].Instances c.Assert(instances, gocheck.HasLen, 0) got, err := getQueue(queueName).Get(1e6) c.Assert(err, gocheck.IsNil) c.Assert(*got, gocheck.DeepEquals, msg) got.Delete() }
func (s *S) TestGrantAccessShouldAddUserToListOfRepositories(c *C) { tmpdir, err := commandmocker.Add("git", "$*") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) r, err := New("proj1", []string{"someuser"}, true) c.Assert(err, IsNil) defer db.Session.Repository().RemoveId(r.Name) r2, err := New("proj2", []string{"otheruser"}, true) c.Assert(err, IsNil) defer db.Session.Repository().RemoveId(r2.Name) u := struct { Name string `bson:"_id"` }{Name: "lolcat"} err = db.Session.User().Insert(&u) c.Assert(err, IsNil) defer db.Session.User().RemoveId(u.Name) err = GrantAccess([]string{r.Name, r2.Name}, []string{u.Name}) c.Assert(err, IsNil) err = db.Session.Repository().FindId(r.Name).One(&r) c.Assert(err, IsNil) err = db.Session.Repository().FindId(r2.Name).One(&r2) c.Assert(err, IsNil) c.Assert(r.Users, DeepEquals, []string{"someuser", u.Name}) c.Assert(r2.Users, DeepEquals, []string{"otheruser", u.Name}) }
func (s *S) TestCollectStatusIDChangeFromPending(c *gocheck.C) { server, url := badGatewayServer() defer server.Close() tmpdir, err := commandmocker.Add("juju", generateOutput(url)) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) p := JujuProvisioner{} collection := p.unitsCollection() defer collection.Close() err = collection.Insert(instance{UnitName: "as_i_rise/0", InstanceID: "pending"}) c.Assert(err, gocheck.IsNil) defer collection.Remove(bson.M{"_id": bson.M{"$in": []string{"as_i_rise/0", "the_infanta/0"}}}) _, err = p.CollectStatus() c.Assert(err, gocheck.IsNil) done := make(chan int8) go func() { for { q := bson.M{"_id": "as_i_rise/0", "instanceid": "i-00000439"} ct, err := collection.Find(q).Count() c.Assert(err, gocheck.IsNil) if ct == 1 { done <- 1 return } runtime.Gosched() } }() select { case <-done: case <-time.After(5e9): c.Fatal("Did not update the unit after 5 seconds.") } }
func (s *ELBSuite) TestRemoveUnitWithELB(c *gocheck.C) { instIds := make([]string, 4) units := make([]provision.Unit, len(instIds)) for i := 0; i < len(instIds); i++ { id := s.server.NewInstance() defer s.server.RemoveInstance(id) instIds[i] = id units[i] = provision.Unit{ Name: "radio/" + strconv.Itoa(i), InstanceId: id, } } tmpdir, err := commandmocker.Add("juju", "unit removed") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) app := testing.NewFakeApp("radio", "rush", 4) manager := ELBManager{} manager.e = s.client err = manager.Create(app) c.Assert(err, gocheck.IsNil) defer manager.Destroy(app) err = manager.Register(app, units...) c.Assert(err, gocheck.IsNil) p := JujuProvisioner{} fUnit := testing.FakeUnit{Name: units[0].Name, InstanceId: units[0].InstanceId} err = p.removeUnit(app, &fUnit) c.Assert(err, gocheck.IsNil) resp, err := s.client.DescribeLoadBalancers(app.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) c.Assert(resp.LoadBalancerDescriptions[0].Instances, gocheck.HasLen, len(units)-1) instance := resp.LoadBalancerDescriptions[0].Instances[0] c.Assert(instance.InstanceId, gocheck.Equals, instIds[1]) }
func (s *ELBSuite) TestDestroyWithELB(c *gocheck.C) { config.Set("juju:charms-path", "/home/charms") defer config.Unset("juju:charms-path") tmpdir, err := commandmocker.Add("juju", "deployed") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) app := testing.NewFakeApp("jimmy", "who", 0) p := JujuProvisioner{} err = p.Provision(app) c.Assert(err, gocheck.IsNil) err = p.Destroy(app) c.Assert(err, gocheck.IsNil) lb := p.LoadBalancer() defer lb.Destroy(app) // sanity addr, err := lb.Addr(app) c.Assert(addr, gocheck.Equals, "") c.Assert(err, gocheck.NotNil) c.Assert(err.Error(), gocheck.Equals, "not found") q := getQueue(queueName) msg, err := q.Get(1e9) c.Assert(err, gocheck.IsNil) if msg.Action == addUnitToLoadBalancer && msg.Args[0] == "jimmy" { msg.Delete() } else { q.Release(msg, 0) } }
func (s *S) TestCollectStatusIDChangeDisabledELB(c *gocheck.C) { tmpdir, err := commandmocker.Add("juju", collectOutput) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) p := JujuProvisioner{} conn, collection := p.unitsCollection() defer conn.Close() err = collection.Insert(instance{UnitName: "as_i_rise/0", InstanceId: "i-00000239"}) c.Assert(err, gocheck.IsNil) defer collection.Remove(bson.M{"_id": bson.M{"$in": []string{"as_i_rise/0", "the_infanta/0"}}}) _, err = p.CollectStatus() c.Assert(err, gocheck.IsNil) done := make(chan int8) go func() { for { q := bson.M{"_id": "as_i_rise/0", "instanceid": "i-00000439"} ct, err := collection.Find(q).Count() c.Assert(err, gocheck.IsNil) if ct == 1 { done <- 1 return } time.Sleep(1e3) } }() select { case <-done: case <-time.After(5e9): c.Fatal("Did not update the unit after 5 seconds.") } }
func (s *S) TestDestroy(c *C) { tmpdir, err := commandmocker.Add("juju", "$*") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) app := NewFakeApp("cribcaged", "python", 3) p := JujuProvisioner{} err = p.Destroy(app) c.Assert(err, IsNil) c.Assert(commandmocker.Ran(tmpdir), Equals, true) expected := []string{ "destroy-service", "cribcaged", "terminate-machine", "1", "terminate-machine", "2", "terminate-machine", "3", } ran := make(chan bool, 1) go func() { for { if reflect.DeepEqual(commandmocker.Parameters(tmpdir), expected) { ran <- true } } }() select { case <-ran: case <-time.After(2e9): c.Errorf("Did not run terminate-machine commands after 2 seconds.") } c.Assert(commandmocker.Parameters(tmpdir), DeepEquals, expected) }
func (s *S) TestRemoveUnits(c *C) { tmpdir, err := commandmocker.Add("juju", "removed") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) app := NewFakeApp("xanadu", "rush", 4) p := JujuProvisioner{} units, err := p.RemoveUnits(app, 3) c.Assert(err, IsNil) expected := []string{ "remove-unit", "xanadu/0", "xanadu/1", "xanadu/2", "terminate-machine", "1", "terminate-machine", "2", "terminate-machine", "3", } ran := make(chan bool, 1) go func() { for { if reflect.DeepEqual(commandmocker.Parameters(tmpdir), expected) { ran <- true } } }() select { case <-ran: case <-time.After(2e9): params := commandmocker.Parameters(tmpdir) c.Fatalf("Did not run terminate-machine commands after 2 seconds. Parameters: %#v", params) } c.Assert(units, DeepEquals, []int{0, 1, 2}) }
func (s *S) TestExecuteCommandUnitDown(c *C) { var buf bytes.Buffer tmpdir, err := commandmocker.Add("juju", "$*") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) app := NewFakeApp("almah", "static", 3) app.units[1].(*FakeUnit).status = provision.StatusDown p := JujuProvisioner{} err = p.ExecuteCommand(&buf, &buf, app, "ls", "-lha") c.Assert(err, IsNil) cmdOutput := "ssh -o StrictHostKeyChecking no -q 1 ls -lha" cmdOutput += "ssh -o StrictHostKeyChecking no -q 3 ls -lha" bufOutput := `Output from unit "almah/0": ssh -o StrictHostKeyChecking no -q 1 ls -lha Output from unit "almah/1": Unit state is "down", it must be "started" for running commands. Output from unit "almah/2": ssh -o StrictHostKeyChecking no -q 3 ls -lha ` c.Assert(commandmocker.Ran(tmpdir), Equals, true) c.Assert(commandmocker.Output(tmpdir), Equals, cmdOutput) c.Assert(buf.String(), Equals, bufOutput) }
func (s *S) TestCollectStatusDirtyOutput(c *C) { tmpdir, err := commandmocker.Add("juju", dirtyCollectOutput) c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) expected := []provision.Unit{ { Name: "as_i_rise/0", AppName: "as_i_rise", Type: "django", Machine: 105, Ip: "10.10.10.163", Status: provision.StatusStarted, }, { Name: "the_infanta/1", AppName: "the_infanta", Type: "gunicorn", Machine: 107, Ip: "10.10.10.168", Status: provision.StatusInstalling, }, } p := JujuProvisioner{} units, err := p.CollectStatus() c.Assert(err, IsNil) if units[0].Type == "gunicorn" { units[0], units[1] = units[1], units[0] } c.Assert(units, DeepEquals, expected) c.Assert(commandmocker.Ran(tmpdir), Equals, true) }
func (s *S) TestRemoveUnit(c *gocheck.C) { tmpdir, err := commandmocker.Add("juju", "removed") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) app := testing.NewFakeApp("two", "rush", 3) p := JujuProvisioner{} conn, collection := p.unitsCollection() defer conn.Close() err = collection.Insert(instance{UnitName: "two/2", InstanceId: "i-00000439"}) c.Assert(err, gocheck.IsNil) err = p.RemoveUnit(app, "two/2") c.Assert(err, gocheck.IsNil) c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) expected := []string{"remove-unit", "two/2", "terminate-machine", "3"} ran := make(chan bool, 1) go func() { for { if reflect.DeepEqual(commandmocker.Parameters(tmpdir), expected) { ran <- true } time.Sleep(1e3) } }() n, err := collection.Find(bson.M{"_id": "two/2"}).Count() c.Assert(err, gocheck.IsNil) c.Assert(n, gocheck.Equals, 0) select { case <-ran: case <-time.After(2e9): c.Errorf("Did not run terminate-machine command after 2 seconds.") } }
func (s *S) TestBootstrapProvisionHealerHeal(c *gocheck.C) { p := JujuProvisioner{} m := machine{ AgentState: "not-started", IpAddress: "localhost", InstanceId: "i-00000376", InstanceState: "running", } p.saveBootstrapMachine(m) conn, collection := p.bootstrapCollection() defer conn.Close() defer collection.Remove(m) sshTmpdir, err := commandmocker.Add("ssh", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(sshTmpdir) sshOutput := []string{ "-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", "localhost", "sudo", "start", "juju-provision-agent", } h := bootstrapProvisionHealer{} err = h.Heal() c.Assert(err, gocheck.IsNil) c.Assert(commandmocker.Ran(sshTmpdir), gocheck.Equals, true) c.Assert(commandmocker.Parameters(sshTmpdir), gocheck.DeepEquals, sshOutput) }
func (s *ELBSuite) TestHandleMessagesWithPendingUnits(c *gocheck.C) { id := s.server.NewInstance() defer s.server.RemoveInstance(id) app := testing.NewFakeApp("2112", "python", 1) router, err := Router() c.Assert(err, gocheck.IsNil) err = router.AddBackend(app.GetName()) defer router.RemoveBackend(app.GetName()) output := strings.Replace(collectOutputNoInstanceID, "i-00004444", id, 1) tmpdir, err := commandmocker.Add("juju", output) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) handle(&queue.Message{ Action: addUnitToLoadBalancer, Args: []string{"2112", "2112/0", "2112/1"}, }) resp, err := s.client.DescribeLoadBalancers(app.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) instances := resp.LoadBalancerDescriptions[0].Instances c.Assert(instances, gocheck.HasLen, 1) c.Assert(instances[0].InstanceId, gocheck.Equals, id) msg, err := getQueue(queueName).Get(5e9) c.Assert(err, gocheck.IsNil) c.Assert(msg.Action, gocheck.Equals, addUnitToLoadBalancer) c.Assert(msg.Args, gocheck.DeepEquals, []string{"2112", "2112/1"}) }
func (s *ELBSuite) TestHandleMessageWithUnits(c *gocheck.C) { id1 := s.server.NewInstance() id2 := s.server.NewInstance() defer s.server.RemoveInstance(id1) defer s.server.RemoveInstance(id2) app := testing.NewFakeApp("symfonia", "python", 1) router, err := Router() c.Assert(err, gocheck.IsNil) router.AddBackend(app.GetName()) c.Assert(err, gocheck.IsNil) defer router.RemoveBackend(app.GetName()) output := strings.Replace(simpleCollectOutput, "i-00004444", id1, -1) output = strings.Replace(output, "i-00004445", id2, -1) tmpdir, err := commandmocker.Add("juju", output) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) msg := queue.Message{ Action: addUnitToLoadBalancer, Args: []string{"symfonia", "symfonia/0", "symfonia/1"}, } handle(&msg) resp, err := s.client.DescribeLoadBalancers(app.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) instances := resp.LoadBalancerDescriptions[0].Instances c.Assert(instances, gocheck.HasLen, 2) ids := []string{instances[0].InstanceId, instances[1].InstanceId} sort.Strings(ids) want := []string{id1, id2} sort.Strings(want) c.Assert(ids, gocheck.DeepEquals, want) c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) }
func (s *ELBSuite) TestHandleMessageWithoutUnits(c *gocheck.C) { instIds := make([]string, 3) for i := 0; i < len(instIds); i++ { id := s.server.NewInstance() defer s.server.RemoveInstance(id) instIds[i] = id } replace := []string{"i-00004444", "i-00004445", "i-00004450"} output := simpleCollectOutput for i, r := range replace { output = strings.Replace(output, r, instIds[i], 1) } tmpdir, err := commandmocker.Add("juju", output) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) app := testing.NewFakeApp("symfonia", "python", 1) router, err := Router() c.Assert(err, gocheck.IsNil) err = router.AddBackend(app.GetName()) c.Assert(err, gocheck.IsNil) defer router.RemoveBackend(app.GetName()) handle(&queue.Message{ Action: addUnitToLoadBalancer, Args: []string{"symfonia"}, }) resp, err := s.client.DescribeLoadBalancers(app.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) instances := resp.LoadBalancerDescriptions[0].Instances c.Assert(instances, gocheck.HasLen, 3) ids := []string{instances[0].InstanceId, instances[1].InstanceId, instances[2].InstanceId} sort.Strings(ids) sort.Strings(instIds) c.Assert(ids, gocheck.DeepEquals, instIds) }
func (s *S) TestBootstrapMachineHealerDontNeedsHeal(c *gocheck.C) { tmpdir, err := commandmocker.Add("juju", collectOutput) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) h := bootstrapMachineHealer{} c.Assert(h.needsHeal(), gocheck.Equals, false) }
func (s *S) TestNewBareShouldCreateADir(c *gocheck.C) { dir, err := commandmocker.Add("git", "$*") c.Check(err, gocheck.IsNil) defer commandmocker.Remove(dir) err = newBare("myBare") c.Assert(err, gocheck.IsNil) c.Assert(commandmocker.Ran(dir), gocheck.Equals, true) }
func (s *S) TestInstanceMachineHealWhenEverythingIsOk(c *gocheck.C) { jujuTmpdir, err := commandmocker.Add("juju", collectOutput) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(jujuTmpdir) sshTmpdir, err := commandmocker.Add("ssh", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(sshTmpdir) jujuOutput := []string{ "status", // for juju status that gets the output } h := instanceMachineHealer{} err = h.Heal() c.Assert(err, gocheck.IsNil) c.Assert(commandmocker.Ran(jujuTmpdir), gocheck.Equals, true) c.Assert(commandmocker.Parameters(jujuTmpdir), gocheck.DeepEquals, jujuOutput) c.Assert(commandmocker.Ran(sshTmpdir), gocheck.Equals, false) }
func (s *ELBSuite) TestCollectStatusWithELBAndIDChange(c *gocheck.C) { a := testing.NewFakeApp("symfonia", "symfonia", 0) p := JujuProvisioner{} router, err := Router() c.Assert(err, gocheck.IsNil) err = router.AddBackend(a.GetName()) c.Assert(err, gocheck.IsNil) defer router.RemoveBackend(a.GetName()) id1 := s.server.NewInstance() defer s.server.RemoveInstance(id1) id2 := s.server.NewInstance() defer s.server.RemoveInstance(id2) id3 := s.server.NewInstance() defer s.server.RemoveInstance(id3) collection := p.unitsCollection() defer collection.Close() err = collection.Insert(instance{UnitName: "symfonia/0", InstanceID: id3}) c.Assert(err, gocheck.IsNil) err = router.AddRoute(a.GetName(), id3) c.Assert(err, gocheck.IsNil) err = router.AddRoute(a.GetName(), id2) c.Assert(err, gocheck.IsNil) q := bson.M{"_id": bson.M{"$in": []string{"symfonia/0", "symfonia/1", "symfonia/2", "raise/0"}}} defer collection.Remove(q) output := strings.Replace(simpleCollectOutput, "i-00004444", id1, 1) output = strings.Replace(output, "i-00004445", id2, 1) tmpdir, err := commandmocker.Add("juju", output) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) _, err = p.CollectStatus() c.Assert(err, gocheck.IsNil) done := make(chan int8) go func() { for { q := bson.M{"_id": "symfonia/0", "instanceid": id1} ct, err := collection.Find(q).Count() c.Assert(err, gocheck.IsNil) if ct == 1 { done <- 1 return } runtime.Gosched() } }() select { case <-done: case <-time.After(5e9): c.Fatal("Did not save the unit after 5 seconds.") } resp, err := s.client.DescribeLoadBalancers(a.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) instances := resp.LoadBalancerDescriptions[0].Instances c.Assert(instances, gocheck.HasLen, 2) c.Assert(instances[0].InstanceId, gocheck.Equals, id2) c.Assert(instances[1].InstanceId, gocheck.Equals, id1) }
func (s *S) TestNewShouldNotStoreRepoInDbWhenBareCreationFails(c *C) { dir, err := commandmocker.Error("git", "", 1) c.Check(err, IsNil) defer commandmocker.Remove(dir) r, err := New("myRepo", []string{"pumpkin"}, true) c.Check(err, NotNil) err = db.Session.Repository().Find(bson.M{"_id": r.Name}).One(&r) c.Assert(err, ErrorMatches, "^not found$") }
func (s *S) TestNewShouldCreateNewGitBareRepository(c *C) { tmpdir, err := commandmocker.Add("git", "$*") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) _, err = New("myRepo", []string{"pumpkin"}, true) c.Assert(err, IsNil) defer db.Session.Repository().Remove(bson.M{"_id": "myRepo"}) c.Assert(commandmocker.Ran(tmpdir), Equals, true) }
func (s *S) TestRestartRouter(c *gocheck.C) { tmpdir, err := commandmocker.Add("sudo", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) err = RestartRouter() c.Assert(err, gocheck.IsNil) c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) expected := "service nginx restart" c.Assert(commandmocker.Output(tmpdir), gocheck.Equals, expected) }
func (s *S) TestNewContainer(c *gocheck.C) { id := "945132e7b4c9" tmpdir, err := commandmocker.Add("docker", id) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) app := testing.NewFakeApp("app-name", "python", 1) container, _ := newContainer(app, deployContainerCmd) c.Assert(container.name, gocheck.Equals, "app-name") c.Assert(container.id, gocheck.Equals, id) }
func (s *S) TestConflictingRepositoryNameShouldReturnExplicitError(c *C) { tmpdir, err := commandmocker.Add("git", "$*") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) _, err = New("someRepo", []string{"gollum"}, true) defer db.Session.Repository().Remove(bson.M{"_id": "someRepo"}) c.Assert(err, IsNil) _, err = New("someRepo", []string{"gollum"}, true) c.Assert(err, ErrorMatches, "A repository with this name already exists.") }
func (s *S) TestImageCommitReturnsImageId(c *gocheck.C) { tmpdir, err := commandmocker.Add("docker", "945132e7b4c9\n") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) img := image{Name: "app-name", Id: "image-id"} id, err := img.commit("container-id") defer img.remove() c.Assert(err, gocheck.IsNil) c.Assert(id, gocheck.Equals, "945132e7b4c9") }
func (s *S) TestNewBareShouldReturnMeaningfullErrorWhenBareCreationFails(c *gocheck.C) { dir, err := commandmocker.Error("git", "cmd output", 1) c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(dir) err = newBare("foo") c.Check(err, gocheck.NotNil) got := err.Error() expected := "Could not create git bare repository: exit status 1. cmd output" c.Assert(got, gocheck.Equals, expected) }
func (s *S) TestLXCDestroy(c *gocheck.C) { tmpdir, err := commandmocker.Add("sudo", "$*") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) container := container{name: "container"} err = container.destroy() c.Assert(err, gocheck.IsNil) c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) expected := "lxc-destroy -n container" c.Assert(commandmocker.Output(tmpdir), gocheck.Equals, expected) }
func (s *S) TestProvision(c *C) { tmpdir, err := commandmocker.Add("juju", "$*") c.Assert(err, IsNil) defer commandmocker.Remove(tmpdir) app := NewFakeApp("trace", "python", 0) p := JujuProvisioner{} err = p.Provision(app) c.Assert(err, IsNil) c.Assert(commandmocker.Ran(tmpdir), Equals, true) c.Assert(commandmocker.Output(tmpdir), Equals, "deploy --repository /home/charms local:python trace") }