LEFT | RIGHT |
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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 // Reset returns environment state to that which existed at the start of | 85 // Reset returns environment state to that which existed at the start of |
86 // the test. | 86 // the test. |
87 func (s *JujuConnSuite) Reset(c *C) { | 87 func (s *JujuConnSuite) Reset(c *C) { |
88 s.tearDownConn(c) | 88 s.tearDownConn(c) |
89 s.setUpConn(c) | 89 s.setUpConn(c) |
90 } | 90 } |
91 | 91 |
92 func (s *JujuConnSuite) StateInfo(c *C) *state.Info { | 92 func (s *JujuConnSuite) StateInfo(c *C) *state.Info { |
93 return &state.Info{ | 93 return &state.Info{ |
94 » » Addrs: []string{testing.MgoAddr}, | 94 » » Addrs: []string{testing.MgoAddr}, |
95 » » Password: "dummy-secret", | 95 » » Password: "dummy-secret", |
96 » » CACertPEM: []byte(testing.CACertPEM), | 96 » » CACert: []byte(testing.CACert), |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 func (s *JujuConnSuite) setUpConn(c *C) { | 100 func (s *JujuConnSuite) setUpConn(c *C) { |
101 if s.RootDir != "" { | 101 if s.RootDir != "" { |
102 panic("JujuConnSuite.setUpConn without teardown") | 102 panic("JujuConnSuite.setUpConn without teardown") |
103 } | 103 } |
104 s.RootDir = c.MkDir() | 104 s.RootDir = c.MkDir() |
105 s.oldHome = os.Getenv("HOME") | 105 s.oldHome = os.Getenv("HOME") |
106 home := filepath.Join(s.RootDir, "/home/ubuntu") | 106 home := filepath.Join(s.RootDir, "/home/ubuntu") |
107 err := os.MkdirAll(home, 0777) | 107 err := os.MkdirAll(home, 0777) |
108 c.Assert(err, IsNil) | 108 c.Assert(err, IsNil) |
109 os.Setenv("HOME", home) | 109 os.Setenv("HOME", home) |
110 | 110 |
111 dataDir := filepath.Join(s.RootDir, "/var/lib/juju") | 111 dataDir := filepath.Join(s.RootDir, "/var/lib/juju") |
112 err = os.MkdirAll(dataDir, 0777) | 112 err = os.MkdirAll(dataDir, 0777) |
113 c.Assert(err, IsNil) | 113 c.Assert(err, IsNil) |
114 | 114 |
115 err = os.Mkdir(filepath.Join(home, ".juju"), 0777) | 115 err = os.Mkdir(filepath.Join(home, ".juju"), 0777) |
116 c.Assert(err, IsNil) | 116 c.Assert(err, IsNil) |
117 | 117 |
118 err = ioutil.WriteFile(filepath.Join(home, ".juju", "environments.yaml")
, config, 0600) | 118 err = ioutil.WriteFile(filepath.Join(home, ".juju", "environments.yaml")
, config, 0600) |
119 c.Assert(err, IsNil) | 119 c.Assert(err, IsNil) |
120 | 120 |
| 121 err = ioutil.WriteFile(filepath.Join(home, ".juju", "dummyenv-cert.pem")
, []byte(testing.CACert), 0666) |
| 122 c.Assert(err, IsNil) |
| 123 |
| 124 err = ioutil.WriteFile(filepath.Join(home, ".juju", "dummyenv-private-ke
y.pem"), []byte(testing.CAKey), 0600) |
| 125 c.Assert(err, IsNil) |
| 126 |
121 environ, err := environs.NewFromName("dummyenv") | 127 environ, err := environs.NewFromName("dummyenv") |
122 c.Assert(err, IsNil) | 128 c.Assert(err, IsNil) |
123 // sanity check we've got the correct environment. | 129 // sanity check we've got the correct environment. |
124 c.Assert(environ.Name(), Equals, "dummyenv") | 130 c.Assert(environ.Name(), Equals, "dummyenv") |
125 » c.Assert(juju.Bootstrap(environ, false, []byte(testing.CACertPEM+testing
.CAKeyPEM)), IsNil) | 131 » c.Assert(environs.Bootstrap(environ, false, []byte(testing.CACert+testin
g.CAKey)), IsNil) |
126 | 132 |
127 conn, err := juju.NewConnFromName("dummyenv") | 133 conn, err := juju.NewConnFromName("dummyenv") |
128 c.Assert(err, IsNil) | 134 c.Assert(err, IsNil) |
129 s.Conn = conn | 135 s.Conn = conn |
130 s.State = conn.State | 136 s.State = conn.State |
131 c.Assert(err, IsNil) | 137 c.Assert(err, IsNil) |
132 } | 138 } |
133 | 139 |
134 func (s *JujuConnSuite) tearDownConn(c *C) { | 140 func (s *JujuConnSuite) tearDownConn(c *C) { |
135 // Bootstrap will set the admin password, and render non-authorized use | 141 // Bootstrap will set the admin password, and render non-authorized use |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm { | 177 func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm { |
172 ch := testing.Charms.Dir("series", name) | 178 ch := testing.Charms.Dir("series", name) |
173 ident := fmt.Sprintf("%s-%d", ch.Meta().Name, ch.Revision()) | 179 ident := fmt.Sprintf("%s-%d", ch.Meta().Name, ch.Revision()) |
174 curl := charm.MustParseURL("local:series/" + ident) | 180 curl := charm.MustParseURL("local:series/" + ident) |
175 repo, err := charm.InferRepository(curl, testing.Charms.Path) | 181 repo, err := charm.InferRepository(curl, testing.Charms.Path) |
176 c.Assert(err, IsNil) | 182 c.Assert(err, IsNil) |
177 sch, err := s.Conn.PutCharm(curl, repo, false) | 183 sch, err := s.Conn.PutCharm(curl, repo, false) |
178 c.Assert(err, IsNil) | 184 c.Assert(err, IsNil) |
179 return sch | 185 return sch |
180 } | 186 } |
LEFT | RIGHT |