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

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package application_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/application"
    12  	"github.com/juju/juju/jujuclient/jujuclienttesting"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type ApplicationConstraintsCommandsSuite struct {
    17  	testing.FakeJujuXDGDataHomeSuite
    18  }
    19  
    20  var _ = gc.Suite(&ApplicationConstraintsCommandsSuite{})
    21  
    22  func (s *ApplicationConstraintsCommandsSuite) TestSetInit(c *gc.C) {
    23  	for _, test := range []struct {
    24  		args []string
    25  		err  string
    26  	}{{
    27  		args: []string{"--application", "mysql", "mem=4G"},
    28  		err:  `option provided but not defined: --application`,
    29  	}, {
    30  		args: []string{"-s", "mysql", "mem=4G"},
    31  		err:  `option provided but not defined: -s`,
    32  	}, {
    33  		args: []string{},
    34  		err:  `no application name specified`,
    35  	}, {
    36  		args: []string{"mysql", "="},
    37  		err:  `malformed constraint "="`,
    38  	}, {
    39  		args: []string{"cpu-power=250"},
    40  		err:  `invalid application name "cpu-power=250"`,
    41  	}, {
    42  		args: []string{"mysql", "cpu-power=250"},
    43  	}} {
    44  		cmd := application.NewApplicationSetConstraintsCommand()
    45  		cmd.SetClientStore(jujuclienttesting.MinimalStore())
    46  		err := cmdtesting.InitCommand(cmd, test.args)
    47  		if test.err == "" {
    48  			c.Check(err, jc.ErrorIsNil)
    49  		} else {
    50  			c.Check(err, gc.ErrorMatches, test.err)
    51  		}
    52  	}
    53  }
    54  
    55  func (s *ApplicationConstraintsCommandsSuite) TestGetInit(c *gc.C) {
    56  	for _, test := range []struct {
    57  		args []string
    58  		err  string
    59  	}{
    60  		{
    61  			args: []string{"-s", "mysql"},
    62  			err:  `option provided but not defined: -s`,
    63  		}, {
    64  			args: []string{"--application", "mysql"},
    65  			err:  `option provided but not defined: --application`,
    66  		}, {
    67  			args: []string{},
    68  			err:  `no application name specified`,
    69  		}, {
    70  			args: []string{"mysql-0"},
    71  			err:  `invalid application name "mysql-0"`,
    72  		}, {
    73  			args: []string{"mysql"},
    74  		},
    75  	} {
    76  		cmd := application.NewApplicationGetConstraintsCommand()
    77  		cmd.SetClientStore(jujuclienttesting.MinimalStore())
    78  		err := cmdtesting.InitCommand(cmd, test.args)
    79  		if test.err == "" {
    80  			c.Check(err, jc.ErrorIsNil)
    81  		} else {
    82  			c.Check(err, gc.ErrorMatches, test.err)
    83  		}
    84  	}
    85  }