1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
jc "github.com/juju/testing/checkers"
11
"github.com/juju/juju/testing"
12
"github.com/juju/juju/worker/uniter/runner/jujuc"
15
type storageAddSuite struct {
19
var _ = gc.Suite(&storageAddSuite{})
21
func (s *storageAddSuite) newHookContext() jujuc.Context {
22
hctx, _ := s.NewHookContext()
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)
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)
39
Usage: storage-add <charm storage name>[=count] ...
47
s.assertOutput(c, ctx, help, "")
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)
61
func (s *storageAddSuite) TestStorageAddInit(c *gc.C) {
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".*`},
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)
79
func (s *storageAddSuite) TestAddUnitStorage(c *gc.C) {
81
{[]string{"data=676"}, 0, ""},
82
{[]string{"data"}, 0, ``},
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)