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

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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 277 }
278 } 278 }
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 var watchMachineInfoTests = []struct { 287 type machineInfo struct {
288 » version version.Version
289 » proposedVersion version.Version
290 » instanceId string
291 }
292
293 var watchMachineTests = []struct {
288 test func(m *state.Machine) error 294 test func(m *state.Machine) error
289 » want *state.MachineInfo 295 » want machineInfo
290 }{ 296 }{
291 { 297 {
292 func(*state.Machine) error { 298 func(*state.Machine) error {
293 return nil 299 return nil
294 }, 300 },
295 » » &state.MachineInfo{}, 301 » » machineInfo{},
296 }, 302 },
297 { 303 {
298 func(m *state.Machine) error { 304 func(m *state.Machine) error {
299 return m.ProposeAgentVersion(version.Version{0, 0, 1}) 305 return m.ProposeAgentVersion(version.Version{0, 0, 1})
300 }, 306 },
301 » » &state.MachineInfo{ 307 » » machineInfo{
302 » » » ProposedAgentVersion: version.Version{0, 0, 1}, 308 » » » proposedVersion: version.Version{0, 0, 1},
303 }, 309 },
304 }, 310 },
305 { 311 {
306 func(m *state.Machine) error { 312 func(m *state.Machine) error {
307 return m.ProposeAgentVersion(version.Version{0, 0, 2}) 313 return m.ProposeAgentVersion(version.Version{0, 0, 2})
308 }, 314 },
309 » » &state.MachineInfo{ 315 » » machineInfo{
310 » » » ProposedAgentVersion: 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: "",
311 }, 335 },
312 }, 336 },
313 { 337 {
314 func(m *state.Machine) error { 338 func(m *state.Machine) error {
315 return m.SetAgentVersion(version.Version{1, 0, 0}) 339 return m.SetAgentVersion(version.Version{1, 0, 0})
316 }, 340 },
317 » » &state.MachineInfo{ 341 » » machineInfo{
318 » » » ProposedAgentVersion: version.Version{0, 0, 2}, 342 » » » proposedVersion: version.Version{0, 0, 2},
319 » » » AgentVersion: version.Version{1, 0, 0}, 343 » » » version: version.Version{1, 0, 0},
320 }, 344 },
321 }, 345 },
322 { 346 {
323 func(m *state.Machine) error { 347 func(m *state.Machine) error {
324 return m.SetAgentVersion(version.Version{1, 0, 1}) 348 return m.SetAgentVersion(version.Version{1, 0, 1})
325 }, 349 },
326 » » &state.MachineInfo{ 350 » » machineInfo{
327 » » » ProposedAgentVersion: version.Version{0, 0, 2}, 351 » » » proposedVersion: version.Version{0, 0, 2},
328 » » » AgentVersion: version.Version{1, 0, 1}, 352 » » » version: version.Version{1, 0, 1},
329 » » }, 353 » » },
330 » }, 354 » },
331 } 355 }
332 356
333 func (s *MachineSuite) TestWatchMachineInfo(c *C) { 357 func (s *MachineSuite) TestWatchMachine(c *C) {
334 » w := s.machine.WatchInfo() 358 » w := s.machine.Watch()
335 defer func() { 359 defer func() {
336 c.Assert(w.Stop(), IsNil) 360 c.Assert(w.Stop(), IsNil)
337 }() 361 }()
338 » for i, test := range watchMachineInfoTests { 362 » for i, test := range watchMachineTests {
339 c.Logf("test %d", i) 363 c.Logf("test %d", i)
340 err := test.test(s.machine) 364 err := test.test(s.machine)
341 c.Assert(err, IsNil) 365 c.Assert(err, IsNil)
342 select { 366 select {
343 » » case got, ok := <-w.Changes(): 367 » » case m, ok := <-w.Changes():
344 c.Assert(ok, Equals, true) 368 c.Assert(ok, Equals, true)
345 » » » c.Assert(got, DeepEquals, test.want) 369 » » » c.Assert(m.Id(), Equals, s.machine.Id())
370 » » » var info machineInfo
371 » » » info.version, err = m.AgentVersion()
372 » » » if _, ok := err.(*state.NotFoundError); !ok {
373 » » » » c.Assert(err, IsNil)
374 » » » }
375 » » » info.proposedVersion, err = m.ProposedAgentVersion()
376 » » » if _, ok := err.(*state.NotFoundError); !ok {
377 » » » » c.Assert(err, IsNil)
378 » » » }
379 » » » info.instanceId, err = m.InstanceId()
380 » » » if _, ok := err.(*state.NotFoundError); !ok {
381 » » » » c.Assert(err, IsNil)
382 » » » }
383 » » » c.Assert(info, Equals, test.want)
346 case <-time.After(500 * time.Millisecond): 384 case <-time.After(500 * time.Millisecond):
347 c.Fatalf("did not get change: %v", test.want) 385 c.Fatalf("did not get change: %v", test.want)
348 } 386 }
349 } 387 }
350 select { 388 select {
351 case got := <-w.Changes(): 389 case got := <-w.Changes():
352 c.Fatalf("got unexpected change: %#v", got) 390 c.Fatalf("got unexpected change: %#v", got)
353 case <-time.After(100 * time.Millisecond): 391 case <-time.After(100 * time.Millisecond):
354 } 392 }
355 } 393 }
LEFTRIGHT

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