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

Delta Between Two Patch Sets: juju/testing/conn.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 | « environs/tools_test.go ('k') | worker/machiner/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 testing 1 package testing
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "io/ioutil" 5 "io/ioutil"
6 . "launchpad.net/gocheck" 6 . "launchpad.net/gocheck"
7 "launchpad.net/juju-core/charm" 7 "launchpad.net/juju-core/charm"
8 "launchpad.net/juju-core/environs" 8 "launchpad.net/juju-core/environs"
9 "launchpad.net/juju-core/environs/dummy" 9 "launchpad.net/juju-core/environs/dummy"
10 "launchpad.net/juju-core/juju" 10 "launchpad.net/juju-core/juju"
11 state "launchpad.net/juju-core/state" 11 state "launchpad.net/juju-core/state"
12 "launchpad.net/juju-core/testing" 12 "launchpad.net/juju-core/testing"
13 "net/url"
14 "os" 13 "os"
15 "path/filepath" 14 "path/filepath"
16 ) 15 )
17 16
18 // JujuConnSuite provides a freshly bootstrapped juju.Conn 17 // JujuConnSuite provides a freshly bootstrapped juju.Conn
19 // for each test. It also includes testing.LoggingSuite. 18 // for each test. It also includes testing.LoggingSuite.
20 // 19 //
21 // It also sets up RootDir to point to a directory hierarchy 20 // It also sets up RootDir to point to a directory hierarchy
22 // mirroring the intended juju directory structure, including 21 // mirroring the intended juju directory structure, including
23 // the following: 22 // the following:
24 // RootDir/home/ubuntu/.juju/environments.yaml 23 // RootDir/home/ubuntu/.juju/environments.yaml
25 // The dummy environments.yaml file, holding 24 // The dummy environments.yaml file, holding
26 // a default environment named "dummyenv" 25 // a default environment named "dummyenv"
27 // which uses the "dummy" environment type. 26 // which uses the "dummy" environment type.
28 // RootDir/var/lib/juju 27 // RootDir/var/lib/juju
29 //» » An empty directory returned as VarDir - the 28 //» » An empty directory returned as DataDir - the
30 // root of the juju data storage space. 29 // root of the juju data storage space.
31 // $HOME is set to point to RootDir/home/ubuntu. 30 // $HOME is set to point to RootDir/home/ubuntu.
32 type JujuConnSuite struct { 31 type JujuConnSuite struct {
33 testing.LoggingSuite 32 testing.LoggingSuite
34 testing.ZkSuite 33 testing.ZkSuite
35 Conn *juju.Conn 34 Conn *juju.Conn
36 State *state.State 35 State *state.State
37 RootDir string // The faked-up root directory. 36 RootDir string // The faked-up root directory.
38 oldHome string 37 oldHome string
39 } 38 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if s.RootDir != "" { 78 if s.RootDir != "" {
80 panic("JujuConnSuite.setUpConn without teardown") 79 panic("JujuConnSuite.setUpConn without teardown")
81 } 80 }
82 s.RootDir = c.MkDir() 81 s.RootDir = c.MkDir()
83 s.oldHome = os.Getenv("HOME") 82 s.oldHome = os.Getenv("HOME")
84 home := filepath.Join(s.RootDir, "/home/ubuntu") 83 home := filepath.Join(s.RootDir, "/home/ubuntu")
85 err := os.MkdirAll(home, 0777) 84 err := os.MkdirAll(home, 0777)
86 c.Assert(err, IsNil) 85 c.Assert(err, IsNil)
87 os.Setenv("HOME", home) 86 os.Setenv("HOME", home)
88 87
89 » varDir := filepath.Join(s.RootDir, "/var/lib/juju") 88 » dataDir := filepath.Join(s.RootDir, "/var/lib/juju")
90 » err = os.MkdirAll(varDir, 0777) 89 » err = os.MkdirAll(dataDir, 0777)
91 c.Assert(err, IsNil) 90 c.Assert(err, IsNil)
92 91
93 err = os.Mkdir(filepath.Join(home, ".juju"), 0777) 92 err = os.Mkdir(filepath.Join(home, ".juju"), 0777)
94 c.Assert(err, IsNil) 93 c.Assert(err, IsNil)
95 94
96 err = ioutil.WriteFile(filepath.Join(home, ".juju", "environments.yaml") , config, 0600) 95 err = ioutil.WriteFile(filepath.Join(home, ".juju", "environments.yaml") , config, 0600)
97 c.Assert(err, IsNil) 96 c.Assert(err, IsNil)
98 97
99 environ, err := environs.NewFromName("dummyenv") 98 environ, err := environs.NewFromName("dummyenv")
100 c.Assert(err, IsNil) 99 c.Assert(err, IsNil)
(...skipping 11 matching lines...) Expand all
112 func (s *JujuConnSuite) tearDownConn(c *C) { 111 func (s *JujuConnSuite) tearDownConn(c *C) {
113 dummy.Reset() 112 dummy.Reset()
114 c.Assert(s.Conn.Close(), IsNil) 113 c.Assert(s.Conn.Close(), IsNil)
115 s.Conn = nil 114 s.Conn = nil
116 s.State = nil 115 s.State = nil
117 os.Setenv("HOME", s.oldHome) 116 os.Setenv("HOME", s.oldHome)
118 s.oldHome = "" 117 s.oldHome = ""
119 s.RootDir = "" 118 s.RootDir = ""
120 } 119 }
121 120
122 func (s *JujuConnSuite) VarDir() string { 121 func (s *JujuConnSuite) DataDir() string {
123 if s.RootDir == "" { 122 if s.RootDir == "" {
124 » » panic("VarDir called out of test context") 123 » » panic("DataDir called out of test context")
125 } 124 }
126 return filepath.Join(s.RootDir, "/var/lib/juju") 125 return filepath.Join(s.RootDir, "/var/lib/juju")
127 } 126 }
128 127
129 // WriteConfig writes a juju config file to the "home" directory. 128 // WriteConfig writes a juju config file to the "home" directory.
130 func (s *JujuConnSuite) WriteConfig(config string) { 129 func (s *JujuConnSuite) WriteConfig(config string) {
131 if s.RootDir == "" { 130 if s.RootDir == "" {
132 panic("SetUpTest has not been called; will not overwrite $HOME/. juju/environments.yaml") 131 panic("SetUpTest has not been called; will not overwrite $HOME/. juju/environments.yaml")
133 } 132 }
134 path := filepath.Join(os.Getenv("HOME"), ".juju", "environments.yaml") 133 path := filepath.Join(os.Getenv("HOME"), ".juju", "environments.yaml")
135 err := ioutil.WriteFile(path, []byte(config), 0600) 134 err := ioutil.WriteFile(path, []byte(config), 0600)
136 if err != nil { 135 if err != nil {
137 panic(err) 136 panic(err)
138 } 137 }
139 } 138 }
140 139
141 func (s *JujuConnSuite) StateInfo(c *C) *state.Info { 140 func (s *JujuConnSuite) StateInfo(c *C) *state.Info {
142 return &state.Info{Addrs: []string{testing.ZkAddr}} 141 return &state.Info{Addrs: []string{testing.ZkAddr}}
143 } 142 }
144 143
145 func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm { 144 func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm {
146 ch := testing.Charms.Dir(name) 145 ch := testing.Charms.Dir(name)
147 ident := fmt.Sprintf("%s-%d", name, ch.Revision()) 146 ident := fmt.Sprintf("%s-%d", name, ch.Revision())
148 curl := charm.MustParseURL("local:series/" + ident) 147 curl := charm.MustParseURL("local:series/" + ident)
149 » bundleURL, err := url.Parse("http://bundles.example.com/" + ident) 148 » sch, err := s.Conn.PutCharm(curl, testing.Charms.Path, false)
150 » c.Assert(err, IsNil)
151 » sch, err := s.State.AddCharm(ch, curl, bundleURL, ident+"-sha256")
152 c.Assert(err, IsNil) 149 c.Assert(err, IsNil)
153 return sch 150 return sch
154 } 151 }
LEFTRIGHT

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