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

Delta Between Two Patch Sets: state/machine_test.go

Issue 6447054: state: implement MachineInfoWatcher
Left Patch Set: state: implement MachineInfoWatcher Created 11 years, 8 months ago
Right Patch Set: state: implement MachineInfoWatcher Created 11 years, 8 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 | « state/machine.go ('k') | state/util.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 state_test 1 package state_test
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/juju-core/state" 6 "launchpad.net/juju-core/state"
7 "launchpad.net/juju-core/version" 7 "launchpad.net/juju-core/version"
8 "sort" 8 "sort"
9 "time" 9 "time"
10 ) 10 )
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 _, err := config.Write() 46 _, err := config.Write()
47 c.Assert(err, IsNil) 47 c.Assert(err, IsNil)
48 48
49 id, err := s.machine.InstanceId() 49 id, err := s.machine.InstanceId()
50 c.Assert(err.Error(), Equals, `invalid type of value map[interface {}]in terface {}{} of instance id of machine 0: map[interface {}]interface {}`) 50 c.Assert(err.Error(), Equals, `invalid type of value map[interface {}]in terface {}{} of instance id of machine 0: map[interface {}]interface {}`)
51 c.Assert(id, Equals, "") 51 c.Assert(id, Equals, "")
52 } 52 }
53 53
54 func (s *MachineSuite) TestMachineInstanceIdMissing(c *C) { 54 func (s *MachineSuite) TestMachineInstanceIdMissing(c *C) {
55 id, err := s.machine.InstanceId() 55 id, err := s.machine.InstanceId()
56 » c.Assert(err, FitsTypeOf, &state.NoInstanceIdError{}) 56 » c.Assert(err, FitsTypeOf, &state.NotFoundError{})
57 c.Assert(id, Equals, "") 57 c.Assert(id, Equals, "")
58 } 58 }
59 59
60 func (s *MachineSuite) TestMachineInstanceIdBlank(c *C) { 60 func (s *MachineSuite) TestMachineInstanceIdBlank(c *C) {
61 config := s.Config(c) 61 config := s.Config(c)
62 config.Set("provider-machine-id", "") 62 config.Set("provider-machine-id", "")
63 _, err := config.Write() 63 _, err := config.Write()
64 c.Assert(err, IsNil) 64 c.Assert(err, IsNil)
65 65
66 id, err := s.machine.InstanceId() 66 id, err := s.machine.InstanceId()
67 » c.Assert(err, FitsTypeOf, &state.NoInstanceIdError{}) 67 » c.Assert(err, FitsTypeOf, &state.NotFoundError{})
68 c.Assert(id, Equals, "") 68 c.Assert(id, Equals, "")
69 } 69 }
70 70
71 func (s *MachineSuite) TestMachineSetInstanceId(c *C) { 71 func (s *MachineSuite) TestMachineSetInstanceId(c *C) {
72 err := s.machine.SetInstanceId("umbrella/0") 72 err := s.machine.SetInstanceId("umbrella/0")
73 c.Assert(err, IsNil) 73 c.Assert(err, IsNil)
74 config := s.Config(c) 74 config := s.Config(c)
75 c.Assert(config.Map(), DeepEquals, map[string]interface{}{"provider-mach ine-id": "umbrella/0"}) 75 c.Assert(config.Map(), DeepEquals, map[string]interface{}{"provider-mach ine-id": "umbrella/0"})
76 } 76 }
77 77
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 func unitNames(units []*state.Unit) (s []string) { 280 func unitNames(units []*state.Unit) (s []string) {
281 for _, u := range units { 281 for _, u := range units {
282 s = append(s, u.Name()) 282 s = append(s, u.Name())
283 } 283 }
284 return 284 return
285 } 285 }
286 286
287 type machineInfo struct { 287 type machineInfo struct {
288 version version.Version 288 version version.Version
289 proposedVersion version.Version 289 proposedVersion version.Version
niemeyer 2012/07/30 15:52:59 Should check a non-version related field too (inst
rog 2012/07/30 17:07:52 Done.
290 instanceId string
290 } 291 }
291 292
292 var watchMachineTests = []struct { 293 var watchMachineTests = []struct {
293 test func(m *state.Machine) error 294 test func(m *state.Machine) error
294 want machineInfo 295 want machineInfo
295 }{ 296 }{
296 { 297 {
297 func(*state.Machine) error { 298 func(*state.Machine) error {
298 return nil 299 return nil
299 }, 300 },
300 machineInfo{}, 301 machineInfo{},
301 }, 302 },
302 { 303 {
303 func(m *state.Machine) error { 304 func(m *state.Machine) error {
304 return m.ProposeAgentVersion(version.Version{0, 0, 1}) 305 return m.ProposeAgentVersion(version.Version{0, 0, 1})
305 }, 306 },
306 machineInfo{ 307 machineInfo{
307 proposedVersion: version.Version{0, 0, 1}, 308 proposedVersion: version.Version{0, 0, 1},
308 }, 309 },
309 }, 310 },
310 { 311 {
311 func(m *state.Machine) error { 312 func(m *state.Machine) error {
312 return m.ProposeAgentVersion(version.Version{0, 0, 2}) 313 return m.ProposeAgentVersion(version.Version{0, 0, 2})
313 }, 314 },
314 machineInfo{ 315 machineInfo{
315 proposedVersion: version.Version{0, 0, 2}, 316 proposedVersion: version.Version{0, 0, 2},
317 },
318 },
319 {
320 func(m *state.Machine) error {
321 return m.SetInstanceId("m-foo")
322 },
323 machineInfo{
324 proposedVersion: version.Version{0, 0, 2},
325 instanceId: "m-foo",
326 },
327 },
328 {
329 func(m *state.Machine) error {
330 return m.SetInstanceId("")
331 },
332 machineInfo{
333 proposedVersion: version.Version{0, 0, 2},
334 instanceId: "",
316 }, 335 },
317 }, 336 },
318 { 337 {
319 func(m *state.Machine) error { 338 func(m *state.Machine) error {
320 return m.SetAgentVersion(version.Version{1, 0, 0}) 339 return m.SetAgentVersion(version.Version{1, 0, 0})
321 }, 340 },
322 machineInfo{ 341 machineInfo{
323 proposedVersion: version.Version{0, 0, 2}, 342 proposedVersion: version.Version{0, 0, 2},
324 version: version.Version{1, 0, 0}, 343 version: version.Version{1, 0, 0},
325 }, 344 },
(...skipping 24 matching lines...) Expand all
350 c.Assert(m.Id(), Equals, s.machine.Id()) 369 c.Assert(m.Id(), Equals, s.machine.Id())
351 var info machineInfo 370 var info machineInfo
352 info.version, err = m.AgentVersion() 371 info.version, err = m.AgentVersion()
353 if _, ok := err.(*state.NotFoundError); !ok { 372 if _, ok := err.(*state.NotFoundError); !ok {
354 c.Assert(err, IsNil) 373 c.Assert(err, IsNil)
355 } 374 }
356 info.proposedVersion, err = m.ProposedAgentVersion() 375 info.proposedVersion, err = m.ProposedAgentVersion()
357 if _, ok := err.(*state.NotFoundError); !ok { 376 if _, ok := err.(*state.NotFoundError); !ok {
358 c.Assert(err, IsNil) 377 c.Assert(err, IsNil)
359 } 378 }
379 info.instanceId, err = m.InstanceId()
380 if _, ok := err.(*state.NotFoundError); !ok {
381 c.Assert(err, IsNil)
382 }
360 c.Assert(info, Equals, test.want) 383 c.Assert(info, Equals, test.want)
361 case <-time.After(500 * time.Millisecond): 384 case <-time.After(500 * time.Millisecond):
362 c.Fatalf("did not get change: %v", test.want) 385 c.Fatalf("did not get change: %v", test.want)
363 } 386 }
364 } 387 }
365 select { 388 select {
366 case got := <-w.Changes(): 389 case got := <-w.Changes():
367 c.Fatalf("got unexpected change: %#v", got) 390 c.Fatalf("got unexpected change: %#v", got)
368 case <-time.After(100 * time.Millisecond): 391 case <-time.After(100 * time.Millisecond):
369 } 392 }
370 } 393 }
LEFTRIGHT

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