Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(712)

Side by Side Diff: container/container_test.go

Issue 6501106: environs: remove VarDir global
Patch Set: environs: remove VarDir global Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 package container_test 1 package container_test
2 2
3 import ( 3 import (
4 "io/ioutil" 4 "io/ioutil"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/juju-core/container" 6 "launchpad.net/juju-core/container"
7 "launchpad.net/juju-core/environs" 7 "launchpad.net/juju-core/environs"
8 "launchpad.net/juju-core/juju/testing" 8 "launchpad.net/juju-core/juju/testing"
9 coretesting "launchpad.net/juju-core/testing" 9 coretesting "launchpad.net/juju-core/testing"
10 "os" 10 "os"
11 "path/filepath" 11 "path/filepath"
12 "regexp" 12 "regexp"
13 stdtesting "testing" 13 stdtesting "testing"
14 ) 14 )
15 15
16 type suite struct { 16 type suite struct {
17 testing.JujuConnSuite 17 testing.JujuConnSuite
18 } 18 }
19 19
20 var _ = Suite(&suite{}) 20 var _ = Suite(&suite{})
21 21
22 func TestPackage(t *stdtesting.T) { 22 func TestPackage(t *stdtesting.T) {
23 coretesting.ZkTestPackage(t) 23 coretesting.ZkTestPackage(t)
24 } 24 }
25 25
26 var _ container.Container = (*container.Simple)(nil)
27
26 func (s *suite) TestDeploy(c *C) { 28 func (s *suite) TestDeploy(c *C) {
27 // make sure there's a jujud "executable" in the path. 29 // make sure there's a jujud "executable" in the path.
28 » binDir := c.MkDir() 30 » varDir := c.MkDir()
29 » exe := filepath.Join(binDir, "jujud") 31 » toolsDir := environs.AgentToolsDir(varDir, "unit-0")
32 » err := os.MkdirAll(toolsDir, 0777)
33 » c.Assert(err, IsNil)
34 » exe := filepath.Join(toolsDir, "jujud")
30 defer os.Setenv("PATH", os.Getenv("PATH")) 35 defer os.Setenv("PATH", os.Getenv("PATH"))
31 » os.Setenv("PATH", binDir+":"+os.Getenv("PATH")) 36 » os.Setenv("PATH", toolsDir+":"+os.Getenv("PATH"))
fwereade 2012/09/10 06:58:30 What's PATH doing in here? I thought there was gen
rog 2012/09/10 19:53:10 For this CL (which is big enough I think) I was tr
32 » err := ioutil.WriteFile(exe, []byte("#!/bin/sh\n"), 0777) 37 » err = ioutil.WriteFile(exe, []byte("#!/bin/sh\n"), 0777)
33 c.Assert(err, IsNil) 38 c.Assert(err, IsNil)
34 39
35 // create a unit to deploy 40 // create a unit to deploy
36 dummy := s.AddTestingCharm(c, "dummy") 41 dummy := s.AddTestingCharm(c, "dummy")
37 service, err := s.State.AddService("dummy", dummy) 42 service, err := s.State.AddService("dummy", dummy)
38 c.Assert(err, IsNil) 43 c.Assert(err, IsNil)
39 unit, err := service.AddUnit() 44 unit, err := service.AddUnit()
40 c.Assert(err, IsNil) 45 c.Assert(err, IsNil)
41 46
42 » oldInitDir, oldVarDir := *container.InitDir, environs.VarDir 47 » initDir := c.MkDir()
43 » defer func() { 48 » cont := container.Simple{
44 » » *container.InitDir, environs.VarDir = oldInitDir, oldVarDir 49 » » VarDir: varDir,
45 » }() 50 » » InitDir: initDir,
46 » *container.InitDir, environs.VarDir = c.MkDir(), c.MkDir() 51 » }
52
53 » err = cont.Deploy(unit)
54 » c.Assert(err, ErrorMatches, `(.|\n)+Unknown job(.|\n)+`)
47 55
48 unitName := "juju-agent-dummy-0" 56 unitName := "juju-agent-dummy-0"
fwereade 2012/09/10 06:58:30 What naming scheme does this conform to?
rog 2012/09/10 19:53:10 The one we were using before. container fixes in t
49 » upstartScript := filepath.Join(*container.InitDir, unitName+".conf") 57 » upstartScript := filepath.Join(cont.InitDir, unitName+".conf")
50
51 » unitDir := filepath.Join(environs.VarDir, "units", "dummy-0")
52
53 » cont := container.Simple
54 » err = cont.Deploy(unit)
55 » c.Assert(err, ErrorMatches, `(.|\n)+Unknown job(.|\n)+`)
56 58
57 data, err := ioutil.ReadFile(upstartScript) 59 data, err := ioutil.ReadFile(upstartScript)
58 c.Assert(err, IsNil) 60 c.Assert(err, IsNil)
59 c.Assert(string(data), Matches, `(.|\n)+`+regexp.QuoteMeta(exe)+` unit - -unit-name(.|\n)+`) 61 c.Assert(string(data), Matches, `(.|\n)+`+regexp.QuoteMeta(exe)+` unit - -unit-name(.|\n)+`)
60 62
61 // We can't check that the unit directory is created, because 63 // We can't check that the unit directory is created, because
62 // it is removed when the call to Deploy fails, but 64 // it is removed when the call to Deploy fails, but
63 // we can check that it is removed. 65 // we can check that it is removed.
64 66
67 unitDir := filepath.Join(cont.VarDir, "units", "dummy-0")
fwereade 2012/09/10 06:58:30 Didn't we agree "agents"?
rog 2012/09/10 19:53:10 as above.
65 err = os.MkdirAll(filepath.Join(unitDir, "foo"), 0777) 68 err = os.MkdirAll(filepath.Join(unitDir, "foo"), 0777)
66 c.Assert(err, IsNil) 69 c.Assert(err, IsNil)
67 70
68 err = cont.Destroy(unit) 71 err = cont.Destroy(unit)
69 c.Assert(err, IsNil) 72 c.Assert(err, IsNil)
70 73
71 _, err = os.Stat(unitDir) 74 _, err = os.Stat(unitDir)
72 c.Assert(err, NotNil) 75 c.Assert(err, NotNil)
73 76
74 _, err = os.Stat(upstartScript) 77 _, err = os.Stat(upstartScript)
75 c.Assert(err, NotNil) 78 c.Assert(err, NotNil)
76 } 79 }
77
78 func (s *suite) TestSimpleToolsDir(c *C) {
79 c.Assert(container.Simple.ToolsDir(nil), Equals, filepath.Join(environs. VarDir, "tools"))
80 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b