github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/uniter/runner/jujuc/testing/status.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/worker/uniter/runner/jujuc" 10 ) 11 12 // Status holds the values for the hook context. 13 type Status struct { 14 UnitStatus jujuc.StatusInfo 15 ServiceStatus jujuc.ServiceStatusInfo 16 } 17 18 // SetServiceStatus builds a service status and sets it on the Status. 19 func (s *Status) SetServiceStatus(service jujuc.StatusInfo, units []jujuc.StatusInfo) { 20 s.ServiceStatus = jujuc.ServiceStatusInfo{ 21 Service: service, 22 Units: units, 23 } 24 } 25 26 // ContextStatus is a test double for jujuc.ContextStatus. 27 type ContextStatus struct { 28 contextBase 29 info *Status 30 } 31 32 // UnitStatus implements jujuc.ContextStatus. 33 func (c *ContextStatus) UnitStatus() (*jujuc.StatusInfo, error) { 34 c.stub.AddCall("UnitStatus") 35 if err := c.stub.NextErr(); err != nil { 36 return nil, errors.Trace(err) 37 } 38 39 return &c.info.UnitStatus, nil 40 } 41 42 // SetUnitStatus implements jujuc.ContextStatus. 43 func (c *ContextStatus) SetUnitStatus(status jujuc.StatusInfo) error { 44 c.stub.AddCall("SetUnitStatus", status) 45 if err := c.stub.NextErr(); err != nil { 46 return errors.Trace(err) 47 } 48 49 c.info.UnitStatus = status 50 return nil 51 } 52 53 // ServiceStatus implements jujuc.ContextStatus. 54 func (c *ContextStatus) ServiceStatus() (jujuc.ServiceStatusInfo, error) { 55 c.stub.AddCall("ServiceStatus") 56 if err := c.stub.NextErr(); err != nil { 57 return jujuc.ServiceStatusInfo{}, errors.Trace(err) 58 } 59 60 return c.info.ServiceStatus, nil 61 } 62 63 // SetServiceStatus implements jujuc.ContextStatus. 64 func (c *ContextStatus) SetServiceStatus(status jujuc.StatusInfo) error { 65 c.stub.AddCall("SetServiceStatus", status) 66 if err := c.stub.NextErr(); err != nil { 67 return errors.Trace(err) 68 } 69 70 c.info.SetServiceStatus(status, nil) 71 return nil 72 }