github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/runner/jujuc/storage-add_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 storageAddSuite struct { 16 storageSuite 17 } 18 19 var _ = gc.Suite(&storageAddSuite{}) 20 21 func (s *storageAddSuite) newHookContext() jujuc.Context { 22 hctx, _ := s.NewHookContext() 23 return hctx 24 } 25 26 func (s *storageAddSuite) getStorageUnitAddCommand(c *gc.C) cmd.Command { 27 hctx := s.newHookContext() 28 com, err := jujuc.NewCommand(hctx, cmdString("storage-add")) 29 c.Assert(err, jc.ErrorIsNil) 30 return com 31 } 32 33 func (s *storageAddSuite) TestHelp(c *gc.C) { 34 com := s.getStorageUnitAddCommand(c) 35 ctx := testing.Context(c) 36 code := cmd.Main(com, ctx, []string{"--help"}) 37 c.Assert(code, gc.Equals, 0) 38 help := ` 39 Usage: storage-add <charm storage name>[=count] ... 40 41 Summary: 42 add storage instances 43 44 Details: 45 `[1:] + 46 jujuc.StorageAddDoc 47 s.assertOutput(c, ctx, help, "") 48 } 49 50 func (s *storageAddSuite) assertOutput(c *gc.C, ctx *cmd.Context, o, e string) { 51 c.Assert(bufferString(ctx.Stdout), gc.Equals, o) 52 c.Assert(bufferString(ctx.Stderr), gc.Equals, e) 53 } 54 55 type tstData struct { 56 args []string 57 code int 58 err string 59 } 60 61 func (s *storageAddSuite) TestStorageAddInit(c *gc.C) { 62 tests := []tstData{ 63 {[]string{}, 1, "storage add requires a storage directive"}, 64 {[]string{"data=-676"}, 1, `.*cannot parse count: count must be gre.*`}, 65 {[]string{"data="}, 1, ".*storage constraints require at least one.*"}, 66 {[]string{"data=pool"}, 1, `.*only count can be specified for "data".*`}, 67 {[]string{"data=pool,1M"}, 1, `.*only count can be specified for "data".*`}, 68 {[]string{"data=1M"}, 1, `.*only count can be specified for "data".*`}, 69 {[]string{"data=2,1M"}, 1, `.*only count can be specified for "data".*`}, 70 {[]string{"cache", "data=2,1M"}, 1, `.*only count can be specified for "data".*`}, 71 } 72 for i, t := range tests { 73 c.Logf("test %d: %#v", i, t.args) 74 com := s.getStorageUnitAddCommand(c) 75 testing.TestInit(c, com, t.args, t.err) 76 } 77 } 78 79 func (s *storageAddSuite) TestAddUnitStorage(c *gc.C) { 80 tests := []tstData{ 81 {[]string{"data=676"}, 0, ""}, 82 {[]string{"data"}, 0, ``}, 83 } 84 85 for i, t := range tests { 86 c.Logf("test %d: %#v", i, t.args) 87 com := s.getStorageUnitAddCommand(c) 88 ctx := testing.Context(c) 89 code := cmd.Main(com, ctx, t.args) 90 c.Assert(code, gc.Equals, t.code) 91 s.assertOutput(c, ctx, "", t.err) 92 } 93 }