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

Unified Diff: state/machine_test.go

Issue 6447054: state: implement MachineInfoWatcher
Patch Set: state: implement MachineInfoWatcher Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/machine.go ('k') | state/util.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/machine_test.go
=== modified file 'state/machine_test.go'
--- state/machine_test.go 2012-07-26 14:04:36 +0000
+++ state/machine_test.go 2012-07-30 17:05:30 +0000
@@ -4,6 +4,7 @@
"fmt"
. "launchpad.net/gocheck"
"launchpad.net/juju-core/state"
+ "launchpad.net/juju-core/version"
"sort"
"time"
)
@@ -46,13 +47,13 @@
c.Assert(err, IsNil)
id, err := s.machine.InstanceId()
- c.Assert(err.Error(), Equals, `invalid type for value map[interface {}]interface {}{} of instance id of machine 0: map[interface {}]interface {}`)
+ c.Assert(err.Error(), Equals, `invalid type of value map[interface {}]interface {}{} of instance id of machine 0: map[interface {}]interface {}`)
c.Assert(id, Equals, "")
}
func (s *MachineSuite) TestMachineInstanceIdMissing(c *C) {
id, err := s.machine.InstanceId()
- c.Assert(err, FitsTypeOf, &state.NoInstanceIdError{})
+ c.Assert(err, FitsTypeOf, &state.NotFoundError{})
c.Assert(id, Equals, "")
}
@@ -63,7 +64,7 @@
c.Assert(err, IsNil)
id, err := s.machine.InstanceId()
- c.Assert(err, FitsTypeOf, &state.NoInstanceIdError{})
+ c.Assert(err, FitsTypeOf, &state.NotFoundError{})
c.Assert(id, Equals, "")
}
@@ -282,3 +283,111 @@
}
return
}
+
+type machineInfo struct {
+ version version.Version
+ proposedVersion version.Version
+ instanceId string
+}
+
+var watchMachineTests = []struct {
+ test func(m *state.Machine) error
+ want machineInfo
+}{
+ {
+ func(*state.Machine) error {
+ return nil
+ },
+ machineInfo{},
+ },
+ {
+ func(m *state.Machine) error {
+ return m.ProposeAgentVersion(version.Version{0, 0, 1})
+ },
+ machineInfo{
+ proposedVersion: version.Version{0, 0, 1},
+ },
+ },
+ {
+ func(m *state.Machine) error {
+ return m.ProposeAgentVersion(version.Version{0, 0, 2})
+ },
+ machineInfo{
+ proposedVersion: version.Version{0, 0, 2},
+ },
+ },
+ {
+ func(m *state.Machine) error {
+ return m.SetInstanceId("m-foo")
+ },
+ machineInfo{
+ proposedVersion: version.Version{0, 0, 2},
+ instanceId: "m-foo",
+ },
+ },
+ {
+ func(m *state.Machine) error {
+ return m.SetInstanceId("")
+ },
+ machineInfo{
+ proposedVersion: version.Version{0, 0, 2},
+ instanceId: "",
+ },
+ },
+ {
+ func(m *state.Machine) error {
+ return m.SetAgentVersion(version.Version{1, 0, 0})
+ },
+ machineInfo{
+ proposedVersion: version.Version{0, 0, 2},
+ version: version.Version{1, 0, 0},
+ },
+ },
+ {
+ func(m *state.Machine) error {
+ return m.SetAgentVersion(version.Version{1, 0, 1})
+ },
+ machineInfo{
+ proposedVersion: version.Version{0, 0, 2},
+ version: version.Version{1, 0, 1},
+ },
+ },
+}
+
+func (s *MachineSuite) TestWatchMachine(c *C) {
+ w := s.machine.Watch()
+ defer func() {
+ c.Assert(w.Stop(), IsNil)
+ }()
+ for i, test := range watchMachineTests {
+ c.Logf("test %d", i)
+ err := test.test(s.machine)
+ c.Assert(err, IsNil)
+ select {
+ case m, ok := <-w.Changes():
+ c.Assert(ok, Equals, true)
+ c.Assert(m.Id(), Equals, s.machine.Id())
+ var info machineInfo
+ info.version, err = m.AgentVersion()
+ if _, ok := err.(*state.NotFoundError); !ok {
+ c.Assert(err, IsNil)
+ }
+ info.proposedVersion, err = m.ProposedAgentVersion()
+ if _, ok := err.(*state.NotFoundError); !ok {
+ c.Assert(err, IsNil)
+ }
+ info.instanceId, err = m.InstanceId()
+ if _, ok := err.(*state.NotFoundError); !ok {
+ c.Assert(err, IsNil)
+ }
+ c.Assert(info, Equals, test.want)
+ case <-time.After(500 * time.Millisecond):
+ c.Fatalf("did not get change: %v", test.want)
+ }
+ }
+ select {
+ case got := <-w.Changes():
+ c.Fatalf("got unexpected change: %#v", got)
+ case <-time.After(100 * time.Millisecond):
+ }
+}
« no previous file with comments | « state/machine.go ('k') | state/util.go » ('j') | no next file with comments »

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