github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/model/set_test.go (about) 1 // Copyright 2014 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" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/apiserver/common" 12 "github.com/juju/juju/cmd/juju/model" 13 "github.com/juju/juju/testing" 14 ) 15 16 type SetSuite struct { 17 fakeEnvSuite 18 } 19 20 var _ = gc.Suite(&SetSuite{}) 21 22 func (s *SetSuite) run(c *gc.C, args ...string) (*cmd.Context, error) { 23 command := model.NewSetCommandForTest(s.fake) 24 return testing.RunCommand(c, command, args...) 25 } 26 27 func (s *SetSuite) TestInit(c *gc.C) { 28 for i, test := range []struct { 29 args []string 30 errorMatch string 31 }{ 32 { 33 errorMatch: "no key, value pairs specified", 34 }, { 35 args: []string{"special"}, 36 errorMatch: `expected "key=value", got "special"`, 37 }, { 38 args: []string{"special=extra", "special=other"}, 39 errorMatch: `key "special" specified more than once`, 40 }, { 41 args: []string{"agent-version=2.0.0"}, 42 errorMatch: "agent-version must be set via upgrade-juju", 43 }, 44 } { 45 c.Logf("test %d", i) 46 setCmd := model.NewSetCommandForTest(s.fake) 47 err := testing.InitCommand(setCmd, test.args) 48 c.Check(err, gc.ErrorMatches, test.errorMatch) 49 } 50 } 51 52 func (s *SetSuite) TestPassesValues(c *gc.C) { 53 _, err := s.run(c, "special=extra", "unknown=foo") 54 c.Assert(err, jc.ErrorIsNil) 55 expected := map[string]interface{}{ 56 "special": "extra", 57 "unknown": "foo", 58 } 59 c.Assert(s.fake.values, jc.DeepEquals, expected) 60 } 61 62 func (s *SetSuite) TestSettingKnownValue(c *gc.C) { 63 _, err := s.run(c, "special=extra", "unknown=foo") 64 c.Assert(err, jc.ErrorIsNil) 65 // Command succeeds, but warning logged. 66 expected := `key "unknown" is not defined in the current model configuration: possible misspelling` 67 c.Check(c.GetTestLog(), jc.Contains, expected) 68 } 69 70 func (s *SetSuite) TestBlockedError(c *gc.C) { 71 s.fake.err = common.OperationBlockedError("TestBlockedError") 72 _, err := s.run(c, "special=extra") 73 c.Assert(err, gc.Equals, cmd.ErrSilent) 74 // msg is logged 75 c.Check(c.GetTestLog(), jc.Contains, "TestBlockedError") 76 }