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