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

Delta Between Two Patch Sets: container/container_test.go

Issue 6501106: environs: remove VarDir global
Left Patch Set: environs: remove VarDir global Created 11 years, 6 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « container/container.go ('k') | container/export_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 » varDir := c.MkDir() 30 » dataDir := c.MkDir()
29 » toolsDir := environs.AgentToolsDir(varDir, "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 » » VarDir: varDir, 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.VarDir, "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 }
LEFTRIGHT

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