github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cmd/juju/storage/poolcreate_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storage_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/cmd/envcmd" 12 "github.com/juju/juju/cmd/juju/storage" 13 _ "github.com/juju/juju/provider/dummy" 14 "github.com/juju/juju/testing" 15 ) 16 17 type PoolCreateSuite struct { 18 SubStorageSuite 19 mockAPI *mockPoolCreateAPI 20 } 21 22 var _ = gc.Suite(&PoolCreateSuite{}) 23 24 func (s *PoolCreateSuite) SetUpTest(c *gc.C) { 25 s.SubStorageSuite.SetUpTest(c) 26 27 s.mockAPI = &mockPoolCreateAPI{} 28 s.PatchValue(storage.GetPoolCreateAPI, func(c *storage.PoolCreateCommand) (storage.PoolCreateAPI, error) { 29 return s.mockAPI, nil 30 }) 31 } 32 33 func runPoolCreate(c *gc.C, args []string) (*cmd.Context, error) { 34 return testing.RunCommand(c, envcmd.Wrap(&storage.PoolCreateCommand{}), args...) 35 } 36 37 func (s *PoolCreateSuite) TestPoolCreateOneArg(c *gc.C) { 38 _, err := runPoolCreate(c, []string{"sunshine"}) 39 c.Check(err, gc.ErrorMatches, "pool creation requires names, provider type and attrs for configuration") 40 } 41 42 func (s *PoolCreateSuite) TestPoolCreateNoArgs(c *gc.C) { 43 _, err := runPoolCreate(c, []string{""}) 44 c.Check(err, gc.ErrorMatches, "pool creation requires names, provider type and attrs for configuration") 45 } 46 47 func (s *PoolCreateSuite) TestPoolCreateTwoArgs(c *gc.C) { 48 _, err := runPoolCreate(c, []string{"sunshine", "lollypop"}) 49 c.Check(err, gc.ErrorMatches, "pool creation requires names, provider type and attrs for configuration") 50 } 51 52 func (s *PoolCreateSuite) TestPoolCreateAttrMissingKey(c *gc.C) { 53 _, err := runPoolCreate(c, []string{"sunshine", "lollypop", "=too"}) 54 c.Check(err, gc.ErrorMatches, `expected "key=value", got "=too"`) 55 } 56 57 func (s *PoolCreateSuite) TestPoolCreateAttrMissingValue(c *gc.C) { 58 _, err := runPoolCreate(c, []string{"sunshine", "lollypop", "something="}) 59 c.Check(err, gc.ErrorMatches, `expected "key=value", got "something="`) 60 } 61 62 func (s *PoolCreateSuite) TestPoolCreateAttrEmptyValue(c *gc.C) { 63 _, err := runPoolCreate(c, []string{"sunshine", "lollypop", `something=""`}) 64 c.Check(err, jc.ErrorIsNil) 65 } 66 67 func (s *PoolCreateSuite) TestPoolCreateOneAttr(c *gc.C) { 68 _, err := runPoolCreate(c, []string{"sunshine", "lollypop", "something=too"}) 69 c.Check(err, jc.ErrorIsNil) 70 } 71 72 func (s *PoolCreateSuite) TestPoolCreateEmptyAttr(c *gc.C) { 73 _, err := runPoolCreate(c, []string{"sunshine", "lollypop", ""}) 74 c.Check(err, gc.ErrorMatches, `expected "key=value", got ""`) 75 } 76 77 func (s *PoolCreateSuite) TestPoolCreateManyAttrs(c *gc.C) { 78 _, err := runPoolCreate(c, []string{"sunshine", "lollypop", "something=too", "another=one"}) 79 c.Check(err, jc.ErrorIsNil) 80 } 81 82 type mockPoolCreateAPI struct { 83 } 84 85 func (s mockPoolCreateAPI) CreatePool(pname, ptype string, pconfig map[string]interface{}) error { 86 return nil 87 } 88 89 func (s mockPoolCreateAPI) Close() error { 90 return nil 91 }