github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/model/constraints_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package model_test
     5  
     6  import (
     7  	"github.com/juju/cmd/cmdtesting"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/cmd/juju/model"
    12  	"github.com/juju/juju/testing"
    13  )
    14  
    15  type ModelConstraintsCommandsSuite struct {
    16  	testing.FakeJujuXDGDataHomeSuite
    17  }
    18  
    19  var _ = gc.Suite(&ModelConstraintsCommandsSuite{})
    20  
    21  func (s *ModelConstraintsCommandsSuite) TestSetInit(c *gc.C) {
    22  	for _, test := range []struct {
    23  		args []string
    24  		err  string
    25  	}{
    26  		{
    27  			args: []string{"-s", "mysql"},
    28  			err:  "option provided but not defined: -s",
    29  		}, {
    30  			args: []string{"="},
    31  			err:  `malformed constraint "="`,
    32  		}, {
    33  			args: []string{"cpu-power=250"},
    34  		},
    35  	} {
    36  		err := cmdtesting.InitCommand(model.NewModelSetConstraintsCommandForTest(), test.args)
    37  		if test.err == "" {
    38  			c.Check(err, jc.ErrorIsNil)
    39  		} else {
    40  			c.Check(err, gc.ErrorMatches, test.err)
    41  		}
    42  	}
    43  }
    44  
    45  func (s *ModelConstraintsCommandsSuite) TestGetInit(c *gc.C) {
    46  	for _, test := range []struct {
    47  		args []string
    48  		err  string
    49  	}{
    50  		{
    51  			args: []string{"-s", "mysql"},
    52  			err:  "option provided but not defined: -s",
    53  		}, {
    54  			args: []string{"mysql"},
    55  			err:  `unrecognized args: \["mysql"\]`,
    56  		}, {
    57  			args: []string{},
    58  		},
    59  	} {
    60  		err := cmdtesting.InitCommand(model.NewModelGetConstraintsCommandForTest(), test.args)
    61  		if test.err == "" {
    62  			c.Check(err, jc.ErrorIsNil)
    63  		} else {
    64  			c.Check(err, gc.ErrorMatches, test.err)
    65  		}
    66  	}
    67  }