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