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