1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"github.com/juju/testing"
12
jc "github.com/juju/testing/checkers"
13
gc "gopkg.in/check.v1"
15
"github.com/juju/juju/payload"
16
"github.com/juju/juju/payload/context"
17
coretesting "github.com/juju/juju/testing"
20
type statusSetSuite struct {
21
testing.IsolationSuite
24
compCtx *stubSetStatusContext
27
cmd *context.StatusSetCmd
30
var _ = gc.Suite(&statusSetSuite{})
32
func (s *statusSetSuite) SetUpTest(c *gc.C) {
33
s.IsolationSuite.SetUpTest(c)
35
s.stub = &testing.Stub{}
36
s.compCtx = &stubSetStatusContext{stub: s.stub}
37
s.ctx = coretesting.Context(c)
39
cmd, err := context.NewStatusSetCmd(s)
40
c.Assert(err, jc.ErrorIsNil)
45
func (s *statusSetSuite) init(c *gc.C, class, id, status string) {
46
err := s.cmd.Init([]string{class, id, status})
47
c.Assert(err, jc.ErrorIsNil)
50
func (s *statusSetSuite) Component(name string) (context.Component, error) {
51
s.stub.AddCall("Component", name)
52
if err := s.stub.NextErr(); err != nil {
53
return nil, errors.Trace(err)
59
func (s *statusSetSuite) TestHelp(c *gc.C) {
60
code := cmd.Main(s.cmd, s.ctx, []string{"--help"})
61
c.Assert(code, gc.Equals, 0)
63
c.Check(s.ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, `
64
Usage: payload-status-set <class> <id> <status>
67
update the status of a payload
70
"payload-status-set" is used to update the current status of a registered payload.
71
The <class> and <id> provided must match a payload that has been previously
72
registered with juju using payload-register. The <status> must be one of the
73
follow: starting, started, stopping, stopped
77
func (s *statusSetSuite) TestTooFewArgs(c *gc.C) {
78
err := s.cmd.Init([]string{})
79
c.Check(err, gc.ErrorMatches, `missing .*`)
81
err = s.cmd.Init([]string{payload.StateRunning})
82
c.Check(err, gc.ErrorMatches, `missing .*`)
85
func (s *statusSetSuite) TestInvalidStatjs(c *gc.C) {
86
s.init(c, "docker", "foo", "created")
87
err := s.cmd.Run(s.ctx)
89
c.Check(err, gc.ErrorMatches, `status .* not supported; expected .*`)
92
func (s *statusSetSuite) TestStatusSet(c *gc.C) {
93
s.init(c, "docker", "foo", payload.StateStopped)
94
err := s.cmd.Run(s.ctx)
96
c.Check(err, jc.ErrorIsNil)
99
type stubSetStatusContext struct {
104
func (s stubSetStatusContext) SetStatus(class, id, status string) error {
105
s.stub.AddCall("SetStatus", class, id, status)
106
if err := s.stub.NextErr(); err != nil {
107
return errors.Trace(err)
113
func (s stubSetStatusContext) Flush() error {
114
s.stub.AddCall("Flush")
115
if err := s.stub.NextErr(); err != nil {
116
return errors.Trace(err)