github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/model/get_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package model_test 5 6 import ( 7 "strings" 8 9 "github.com/juju/cmd" 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/cmd/juju/model" 14 "github.com/juju/juju/testing" 15 ) 16 17 type GetSuite struct { 18 fakeEnvSuite 19 } 20 21 var _ = gc.Suite(&GetSuite{}) 22 23 func (s *GetSuite) run(c *gc.C, args ...string) (*cmd.Context, error) { 24 command := model.NewGetCommandForTest(s.fake) 25 return testing.RunCommand(c, command, args...) 26 } 27 28 func (s *GetSuite) TestInit(c *gc.C) { 29 // zero or one args is fine. 30 err := testing.InitCommand(model.NewGetCommandForTest(s.fake), nil) 31 c.Check(err, jc.ErrorIsNil) 32 err = testing.InitCommand(model.NewGetCommandForTest(s.fake), []string{"one"}) 33 c.Check(err, jc.ErrorIsNil) 34 // More than one is not allowed. 35 err = testing.InitCommand(model.NewGetCommandForTest(s.fake), []string{"one", "two"}) 36 c.Check(err, gc.ErrorMatches, `unrecognized args: \["two"\]`) 37 } 38 39 func (s *GetSuite) TestSingleValue(c *gc.C) { 40 context, err := s.run(c, "name") 41 c.Assert(err, jc.ErrorIsNil) 42 43 output := strings.TrimSpace(testing.Stdout(context)) 44 c.Assert(output, gc.Equals, "test-model") 45 } 46 47 func (s *GetSuite) TestSingleValueJSON(c *gc.C) { 48 context, err := s.run(c, "--format=json", "name") 49 c.Assert(err, jc.ErrorIsNil) 50 51 output := strings.TrimSpace(testing.Stdout(context)) 52 c.Assert(output, gc.Equals, `"test-model"`) 53 } 54 55 func (s *GetSuite) TestAllValues(c *gc.C) { 56 context, err := s.run(c) 57 c.Assert(err, jc.ErrorIsNil) 58 59 output := strings.TrimSpace(testing.Stdout(context)) 60 expected := "" + 61 "name: test-model\n" + 62 "running: true\n" + 63 "special: special value" 64 c.Assert(output, gc.Equals, expected) 65 } 66 67 func (s *GetSuite) TestAllValuesJSON(c *gc.C) { 68 context, err := s.run(c, "--format=json") 69 c.Assert(err, jc.ErrorIsNil) 70 71 output := strings.TrimSpace(testing.Stdout(context)) 72 expected := `{"name":"test-model","running":true,"special":"special value"}` 73 c.Assert(output, gc.Equals, expected) 74 }