本文整理汇总了Golang中github.com/juju/core/state.Service.AllUnits方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.AllUnits方法的具体用法?Golang Service.AllUnits怎么用?Golang Service.AllUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/core/state.Service
的用法示例。
在下文中一共展示了Service.AllUnits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addRU
func addRU(c *gc.C, svc *state.Service, rel *state.Relation, principal *state.Unit) (*state.Unit, *state.RelationUnit) {
// Given the service svc in the relation rel, add a unit of svc and create
// a RelationUnit with rel. If principal is supplied, svc is assumed to be
// subordinate and the unit will be created by temporarily entering the
// relation's scope as the principal.
var u *state.Unit
if principal == nil {
unit, err := svc.AddUnit()
c.Assert(err, gc.IsNil)
u = unit
} else {
origUnits, err := svc.AllUnits()
c.Assert(err, gc.IsNil)
pru, err := rel.Unit(principal)
c.Assert(err, gc.IsNil)
err = pru.EnterScope(nil) // to create the subordinate
c.Assert(err, gc.IsNil)
err = pru.LeaveScope() // to reset to initial expected state
c.Assert(err, gc.IsNil)
newUnits, err := svc.AllUnits()
c.Assert(err, gc.IsNil)
for _, unit := range newUnits {
found := false
for _, old := range origUnits {
if unit.Name() == old.Name() {
found = true
break
}
}
if !found {
u = unit
break
}
}
c.Assert(u, gc.NotNil)
}
preventUnitDestroyRemove(c, u)
ru, err := rel.Unit(u)
c.Assert(err, gc.IsNil)
return u, ru
}
示例2: assertAllUnits
func assertAllUnits(c *gc.C, service *state.Service, expected int) {
units, err := service.AllUnits()
c.Assert(err, gc.IsNil)
c.Assert(units, gc.HasLen, expected)
}