Index: state/api/machiner/machiner_test.go |
=== modified file 'state/api/machiner/machiner_test.go' |
--- state/api/machiner/machiner_test.go 2013-06-06 17:55:14 +0000 |
+++ state/api/machiner/machiner_test.go 2013-06-20 07:27:53 +0000 |
@@ -9,9 +9,7 @@ |
"launchpad.net/juju-core/juju/testing" |
"launchpad.net/juju-core/state" |
"launchpad.net/juju-core/state/api" |
- "launchpad.net/juju-core/state/api/machiner" |
"launchpad.net/juju-core/state/api/params" |
- "launchpad.net/juju-core/state/apiserver" |
coretesting "launchpad.net/juju-core/testing" |
stdtesting "testing" |
) |
@@ -22,80 +20,42 @@ |
type machinerSuite struct { |
testing.JujuConnSuite |
- |
- server *apiserver.Server |
- st *api.State |
- |
- machine *state.Machine |
- machiner *machiner.Machiner |
+ st *api.State |
+ machine *state.Machine |
} |
var _ = Suite(&machinerSuite{}) |
-func defaultPassword(stm *state.Machine) string { |
- return stm.Tag() + " password" |
-} |
- |
func (s *machinerSuite) SetUpTest(c *C) { |
s.JujuConnSuite.SetUpTest(c) |
- // Create a machine so we can login as its agent. |
+ // Create a machine so we can log in as its agent. |
var err error |
s.machine, err = s.State.AddMachine("series", state.JobHostUnits) |
c.Assert(err, IsNil) |
- err = s.machine.SetPassword(defaultPassword(s.machine)) |
- |
- // Start the testing API server. |
- s.server, err = apiserver.NewServer( |
- s.State, |
- "localhost:12345", |
- []byte(coretesting.ServerCert), |
- []byte(coretesting.ServerKey), |
- ) |
- c.Assert(err, IsNil) |
- |
- // Login as the machine agent of the created machine. |
- _, info, err := s.APIConn.Environ.StateInfo() |
- c.Assert(err, IsNil) |
- info.Tag = s.machine.Tag() |
- info.Password = defaultPassword(s.machine) |
- c.Logf("opening state; entity %q, password %q", info.Tag, info.Password) |
- s.st, err = api.Open(info) |
- c.Assert(err, IsNil) |
- c.Assert(s.st, NotNil) |
- |
- // Create the machiner facade. |
- s.machiner, err = s.st.Machiner() |
- c.Assert(err, IsNil) |
- c.Assert(s.machiner, NotNil) |
+ err = s.machine.SetPassword("password") |
+ s.st = s.OpenAPIAs(c, s.machine.Tag(), "password") |
} |
func (s *machinerSuite) TearDownTest(c *C) { |
- var err error |
- if s.st != nil { |
- err = s.st.Close() |
- c.Assert(err, IsNil) |
- } |
- if s.server != nil { |
- err = s.server.Stop() |
- c.Assert(err, IsNil) |
- } |
+ err := s.st.Close() |
+ c.Assert(err, IsNil) |
s.JujuConnSuite.TearDownTest(c) |
} |
func (s *machinerSuite) TestMachineAndMachineId(c *C) { |
- machine, err := s.machiner.Machine("42") |
+ machine, err := s.st.Machiner().Machine("42") |
c.Assert(err, ErrorMatches, "machine 42 not found") |
c.Assert(api.ErrCode(err), Equals, api.CodeNotFound) |
c.Assert(machine, IsNil) |
- machine, err = s.machiner.Machine("0") |
+ machine, err = s.st.Machiner().Machine("0") |
c.Assert(err, IsNil) |
c.Assert(machine.Id(), Equals, "0") |
} |
func (s *machinerSuite) TestSetStatus(c *C) { |
- machine, err := s.machiner.Machine("0") |
+ machine, err := s.st.Machiner().Machine("0") |
c.Assert(err, IsNil) |
status, info, err := s.machine.Status() |
@@ -115,7 +75,7 @@ |
func (s *machinerSuite) TestEnsureDead(c *C) { |
c.Assert(s.machine.Life(), Equals, state.Alive) |
- machine, err := s.machiner.Machine("0") |
+ machine, err := s.st.Machiner().Machine("0") |
c.Assert(err, IsNil) |
err = machine.EnsureDead() |
@@ -142,7 +102,7 @@ |
} |
func (s *machinerSuite) TestRefresh(c *C) { |
- machine, err := s.machiner.Machine("0") |
+ machine, err := s.st.Machiner().Machine("0") |
c.Assert(err, IsNil) |
c.Assert(machine.Life(), Equals, params.Life("alive")) |