本文整理匯總了Golang中github.com/juju/juju/state.Relation.Unit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Relation.Unit方法的具體用法?Golang Relation.Unit怎麽用?Golang Relation.Unit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/state.Relation
的用法示例。
在下文中一共展示了Relation.Unit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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, jc.ErrorIsNil)
u = unit
} else {
origUnits, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
pru, err := rel.Unit(principal)
c.Assert(err, jc.ErrorIsNil)
err = pru.EnterScope(nil) // to create the subordinate
c.Assert(err, jc.ErrorIsNil)
err = pru.LeaveScope() // to reset to initial expected state
c.Assert(err, jc.ErrorIsNil)
newUnits, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
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, jc.ErrorIsNil)
return u, ru
}