OLD | NEW |
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 } | 97 } |
97 } | 98 } |
98 | 99 |
99 func (s *JujuConnSuite) setUpConn(c *C) { | 100 func (s *JujuConnSuite) setUpConn(c *C) { |
100 if s.RootDir != "" { | 101 if s.RootDir != "" { |
101 panic("JujuConnSuite.setUpConn without teardown") | 102 panic("JujuConnSuite.setUpConn without teardown") |
102 } | 103 } |
103 s.RootDir = c.MkDir() | 104 s.RootDir = c.MkDir() |
104 s.oldHome = os.Getenv("HOME") | 105 s.oldHome = os.Getenv("HOME") |
105 home := filepath.Join(s.RootDir, "/home/ubuntu") | 106 home := filepath.Join(s.RootDir, "/home/ubuntu") |
106 err := os.MkdirAll(home, 0777) | 107 err := os.MkdirAll(home, 0777) |
107 c.Assert(err, IsNil) | 108 c.Assert(err, IsNil) |
108 os.Setenv("HOME", home) | 109 os.Setenv("HOME", home) |
109 | 110 |
110 dataDir := filepath.Join(s.RootDir, "/var/lib/juju") | 111 dataDir := filepath.Join(s.RootDir, "/var/lib/juju") |
111 err = os.MkdirAll(dataDir, 0777) | 112 err = os.MkdirAll(dataDir, 0777) |
112 c.Assert(err, IsNil) | 113 c.Assert(err, IsNil) |
113 | 114 |
114 err = os.Mkdir(filepath.Join(home, ".juju"), 0777) | 115 err = os.Mkdir(filepath.Join(home, ".juju"), 0777) |
115 c.Assert(err, IsNil) | 116 c.Assert(err, IsNil) |
116 | 117 |
117 err = ioutil.WriteFile(filepath.Join(home, ".juju", "environments.yaml")
, config, 0600) | 118 err = ioutil.WriteFile(filepath.Join(home, ".juju", "environments.yaml")
, config, 0600) |
118 c.Assert(err, IsNil) | 119 c.Assert(err, IsNil) |
119 | 120 |
120 err = ioutil.WriteFile(filepath.Join(home, ".juju", "dummyenv-cert.pem")
, []byte(testing.CACertPEM), 0666) | |
121 c.Assert(err, IsNil) | |
122 | |
123 err = ioutil.WriteFile(filepath.Join(home, ".juju", "dummyenv-private-ke
y.pem"), []byte(testing.CAKeyPEM), 0600) | |
124 c.Assert(err, IsNil) | |
125 | |
126 environ, err := environs.NewFromName("dummyenv") | 121 environ, err := environs.NewFromName("dummyenv") |
127 c.Assert(err, IsNil) | 122 c.Assert(err, IsNil) |
128 // sanity check we've got the correct environment. | 123 // sanity check we've got the correct environment. |
129 c.Assert(environ.Name(), Equals, "dummyenv") | 124 c.Assert(environ.Name(), Equals, "dummyenv") |
130 c.Assert(juju.Bootstrap(environ, false, []byte(testing.CACertPEM+testing
.CAKeyPEM)), IsNil) | 125 c.Assert(juju.Bootstrap(environ, false, []byte(testing.CACertPEM+testing
.CAKeyPEM)), IsNil) |
131 | 126 |
132 conn, err := juju.NewConnFromName("dummyenv") | 127 conn, err := juju.NewConnFromName("dummyenv") |
133 c.Assert(err, IsNil) | 128 c.Assert(err, IsNil) |
134 s.Conn = conn | 129 s.Conn = conn |
135 s.State = conn.State | 130 s.State = conn.State |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm { | 171 func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm { |
177 ch := testing.Charms.Dir("series", name) | 172 ch := testing.Charms.Dir("series", name) |
178 ident := fmt.Sprintf("%s-%d", ch.Meta().Name, ch.Revision()) | 173 ident := fmt.Sprintf("%s-%d", ch.Meta().Name, ch.Revision()) |
179 curl := charm.MustParseURL("local:series/" + ident) | 174 curl := charm.MustParseURL("local:series/" + ident) |
180 repo, err := charm.InferRepository(curl, testing.Charms.Path) | 175 repo, err := charm.InferRepository(curl, testing.Charms.Path) |
181 c.Assert(err, IsNil) | 176 c.Assert(err, IsNil) |
182 sch, err := s.Conn.PutCharm(curl, repo, false) | 177 sch, err := s.Conn.PutCharm(curl, repo, false) |
183 c.Assert(err, IsNil) | 178 c.Assert(err, IsNil) |
184 return sch | 179 return sch |
185 } | 180 } |
OLD | NEW |