LEFT | RIGHT |
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 dataDir := c.MkDir() | 30 dataDir := c.MkDir() |
29 toolsDir := environs.AgentToolsDir(dataDir, "unit-0") | 31 toolsDir := environs.AgentToolsDir(dataDir, "unit-0") |
30 err := os.MkdirAll(toolsDir, 0777) | 32 err := os.MkdirAll(toolsDir, 0777) |
31 c.Assert(err, IsNil) | 33 c.Assert(err, IsNil) |
32 exe := filepath.Join(toolsDir, "jujud") | 34 exe := filepath.Join(toolsDir, "jujud") |
33 defer os.Setenv("PATH", os.Getenv("PATH")) | 35 defer os.Setenv("PATH", os.Getenv("PATH")) |
34 os.Setenv("PATH", toolsDir+":"+os.Getenv("PATH")) | 36 os.Setenv("PATH", toolsDir+":"+os.Getenv("PATH")) |
35 err = ioutil.WriteFile(exe, []byte("#!/bin/sh\n"), 0777) | 37 err = ioutil.WriteFile(exe, []byte("#!/bin/sh\n"), 0777) |
36 c.Assert(err, IsNil) | 38 c.Assert(err, IsNil) |
37 | 39 |
38 // create a unit to deploy | 40 // create a unit to deploy |
39 dummy := s.AddTestingCharm(c, "dummy") | 41 dummy := s.AddTestingCharm(c, "dummy") |
40 service, err := s.State.AddService("dummy", dummy) | 42 service, err := s.State.AddService("dummy", dummy) |
41 c.Assert(err, IsNil) | 43 c.Assert(err, IsNil) |
42 unit, err := service.AddUnit() | 44 unit, err := service.AddUnit() |
43 c.Assert(err, IsNil) | 45 c.Assert(err, IsNil) |
44 | 46 |
45 initDir := c.MkDir() | 47 initDir := c.MkDir() |
46 » cfg := container.Config{ | 48 » cont := container.Simple{ |
47 DataDir: dataDir, | 49 DataDir: dataDir, |
48 InitDir: initDir, | 50 InitDir: initDir, |
49 } | 51 } |
50 | 52 |
51 » err = container.Deploy(cfg, unit) | 53 » err = cont.Deploy(unit) |
52 c.Assert(err, ErrorMatches, `(.|\n)+Unknown job(.|\n)+`) | 54 c.Assert(err, ErrorMatches, `(.|\n)+Unknown job(.|\n)+`) |
53 | 55 |
54 unitName := "juju-agent-dummy-0" | 56 unitName := "juju-agent-dummy-0" |
55 » upstartScript := filepath.Join(cfg.InitDir, unitName+".conf") | 57 » upstartScript := filepath.Join(cont.InitDir, unitName+".conf") |
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 |
65 » unitDir := filepath.Join(cfg.DataDir, "units", "dummy-0") | 67 » unitDir := filepath.Join(cont.DataDir, "units", "dummy-0") |
66 err = os.MkdirAll(filepath.Join(unitDir, "foo"), 0777) | 68 err = os.MkdirAll(filepath.Join(unitDir, "foo"), 0777) |
67 c.Assert(err, IsNil) | 69 c.Assert(err, IsNil) |
68 | 70 |
69 » err = container.Destroy(cfg, unit) | 71 » err = cont.Destroy(unit) |
70 c.Assert(err, IsNil) | 72 c.Assert(err, IsNil) |
71 | 73 |
72 _, err = os.Stat(unitDir) | 74 _, err = os.Stat(unitDir) |
73 c.Assert(err, NotNil) | 75 c.Assert(err, NotNil) |
74 | 76 |
75 _, err = os.Stat(upstartScript) | 77 _, err = os.Stat(upstartScript) |
76 c.Assert(err, NotNil) | 78 c.Assert(err, NotNil) |
77 } | 79 } |
LEFT | RIGHT |