Example #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)
	}
}
Example #2
0
File: payloads.go Project: 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
}
Example #3
0
File: unit.go Project: 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
}
Example #4
0
func (s *statusSuite) TestValidateStateBadState(c *gc.C) {
	state := "some bogus state"
	err := payload.ValidateState(state)

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

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