示例#1
0
func (s *statusSuite) TestValidateStateOkay(c *gc.C) {
	for _, state := range okayStates {
		c.Logf("checking %q", state)
		err := payload.ValidateState(state)

		c.Check(err, jc.ErrorIsNil)
	}
}
示例#2
0
文件: payloads.go 项目: bac/juju
// SetStatus updates the raw status for the identified payload to the
// provided value. If the payload is missing then payload.ErrNotFound
// is returned.
func (up UnitPayloads) SetStatus(name, status string) error {
	if err := payload.ValidateState(status); err != nil {
		return errors.Trace(err)
	}

	change := payloadSetStatusChange{
		Unit:   up.unit,
		Name:   name,
		Status: status,
	}
	if err := Apply(up.db, change); err != nil {
		return errors.Trace(err)
	}
	return nil
}
示例#3
0
文件: unit.go 项目: imoapps/juju
// SetStatus updates the raw status for the identified payload to the
// provided value.
func (uw UnitPayloads) SetStatus(id, status string) error {
	logger.Tracef("setting payload status for %q to %q", id, status)

	if err := payload.ValidateState(status); err != nil {
		return errors.Trace(err)
	}

	found, err := uw.Persist.SetStatus(id, status)
	if err != nil {
		return errors.Trace(err)
	}
	if !found {
		return errors.NotFoundf(id)
	}
	return nil
}
示例#4
0
func (s *statusSuite) TestValidateStateBadState(c *gc.C) {
	state := "some bogus state"
	err := payload.ValidateState(state)

	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
示例#5
0
func (s *statusSuite) TestValidateStateUndefined(c *gc.C) {
	var state string
	err := payload.ValidateState(state)

	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
示例#6
0
func (c *StatusSetCmd) validate(ctx *cmd.Context) error {
	return payload.ValidateState(c.status)
}