github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/machine/flags_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package machine_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/cmd/juju/machine"
    11  	"github.com/juju/juju/storage"
    12  	"github.com/juju/juju/testing"
    13  )
    14  
    15  type FlagsSuite struct {
    16  	testing.BaseSuite
    17  }
    18  
    19  var _ = gc.Suite(&FlagsSuite{})
    20  
    21  func (*FlagsSuite) TestDisksFlagErrors(c *gc.C) {
    22  	var disks []storage.Constraints
    23  	f := machine.NewDisksFlag(&disks)
    24  	err := f.Set("-1")
    25  	c.Assert(err, gc.ErrorMatches, `cannot parse disk constraints: cannot parse count: count must be greater than zero, got "-1"`)
    26  	c.Assert(disks, gc.HasLen, 0)
    27  }
    28  
    29  func (*FlagsSuite) TestDisksFlag(c *gc.C) {
    30  	var disks []storage.Constraints
    31  	f := machine.NewDisksFlag(&disks)
    32  	err := f.Set("crystal,1G")
    33  	c.Assert(err, jc.ErrorIsNil)
    34  	err = f.Set("2,2G")
    35  	c.Assert(err, jc.ErrorIsNil)
    36  	c.Assert(disks, gc.DeepEquals, []storage.Constraints{
    37  		{Pool: "crystal", Size: 1024, Count: 1},
    38  		{Size: 2048, Count: 2},
    39  	})
    40  }