github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/runner/jujuc/status-set_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package jujuc_test 5 6 import ( 7 "github.com/juju/cmd" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/testing" 12 "github.com/juju/juju/worker/uniter/runner/jujuc" 13 ) 14 15 type statusSetSuite struct { 16 ContextSuite 17 } 18 19 var _ = gc.Suite(&statusSetSuite{}) 20 21 func (s *statusSetSuite) SetUpTest(c *gc.C) { 22 s.ContextSuite.SetUpTest(c) 23 } 24 25 var statusSetInitTests = []struct { 26 args []string 27 err string 28 }{ 29 {[]string{"maintenance"}, ""}, 30 {[]string{"maintenance", ""}, ""}, 31 {[]string{"maintenance", "hello"}, ""}, 32 {[]string{}, `invalid args, require <status> \[message\]`}, 33 {[]string{"maintenance", "hello", "extra"}, `unrecognized args: \["extra"\]`}, 34 {[]string{"foo", "hello"}, `invalid status "foo", expected one of \[maintenance blocked waiting active\]`}, 35 } 36 37 func (s *statusSetSuite) TestStatusSetInit(c *gc.C) { 38 for i, t := range statusSetInitTests { 39 c.Logf("test %d: %#v", i, t.args) 40 hctx := s.GetStatusHookContext(c) 41 com, err := jujuc.NewCommand(hctx, cmdString("status-set")) 42 c.Assert(err, jc.ErrorIsNil) 43 testing.TestInit(c, com, t.args, t.err) 44 } 45 } 46 47 func (s *statusSetSuite) TestHelp(c *gc.C) { 48 hctx := s.GetStatusHookContext(c) 49 com, err := jujuc.NewCommand(hctx, cmdString("status-set")) 50 c.Assert(err, jc.ErrorIsNil) 51 ctx := testing.Context(c) 52 code := cmd.Main(com, ctx, []string{"--help"}) 53 c.Assert(code, gc.Equals, 0) 54 expectedHelp := "" + 55 "Usage: status-set [options] <maintenance | blocked | waiting | active> [message]\n" + 56 "\n" + 57 "Summary:\n" + 58 "set status information\n" + 59 "\n" + 60 "Options:\n" + 61 "--service, --application (= false)\n" + 62 " set this status for the application to which the unit belongs if the unit is the leader\n" + 63 "\n" + 64 "Details:\n" + 65 "Sets the workload status of the charm. Message is optional.\n" + 66 "The \"last updated\" attribute of the status is set, even if the\n" + 67 "status and message are the same as what's already set.\n" 68 69 c.Assert(bufferString(ctx.Stdout), gc.Equals, expectedHelp) 70 c.Assert(bufferString(ctx.Stderr), gc.Equals, "") 71 } 72 73 func (s *statusSetSuite) TestStatus(c *gc.C) { 74 for i, args := range [][]string{ 75 []string{"maintenance", "doing some work"}, 76 []string{"active", ""}, 77 } { 78 c.Logf("test %d: %#v", i, args) 79 hctx := s.GetStatusHookContext(c) 80 com, err := jujuc.NewCommand(hctx, cmdString("status-set")) 81 c.Assert(err, jc.ErrorIsNil) 82 ctx := testing.Context(c) 83 code := cmd.Main(com, ctx, args) 84 c.Assert(code, gc.Equals, 0) 85 c.Assert(bufferString(ctx.Stderr), gc.Equals, "") 86 c.Assert(bufferString(ctx.Stdout), gc.Equals, "") 87 status, err := hctx.UnitStatus() 88 c.Assert(err, jc.ErrorIsNil) 89 c.Assert(status.Status, gc.Equals, args[0]) 90 c.Assert(status.Info, gc.Equals, args[1]) 91 } 92 } 93 94 func (s *statusSetSuite) TestServiceStatus(c *gc.C) { 95 for i, args := range [][]string{ 96 []string{"--application", "maintenance", "doing some work"}, 97 []string{"--application", "active", ""}, 98 []string{"--service", "maintenance", "doing some work"}, 99 } { 100 c.Logf("test %d: %#v", i, args) 101 hctx := s.GetStatusHookContext(c) 102 com, err := jujuc.NewCommand(hctx, cmdString("status-set")) 103 c.Assert(err, jc.ErrorIsNil) 104 ctx := testing.Context(c) 105 code := cmd.Main(com, ctx, args) 106 c.Assert(code, gc.Equals, 0) 107 c.Assert(bufferString(ctx.Stderr), gc.Equals, "") 108 c.Assert(bufferString(ctx.Stdout), gc.Equals, "") 109 status, err := hctx.ApplicationStatus() 110 c.Assert(err, jc.ErrorIsNil) 111 c.Assert(status.Application.Status, gc.Equals, args[1]) 112 c.Assert(status.Application.Info, gc.Equals, args[2]) 113 c.Assert(status.Units, jc.DeepEquals, []jujuc.StatusInfo{}) 114 115 } 116 }