github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/backups/list_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups_test 5 6 import ( 7 "strings" 8 9 "github.com/juju/cmd/cmdtesting" 10 "github.com/juju/errors" 11 jc "github.com/juju/testing/checkers" 12 gc "gopkg.in/check.v1" 13 14 "github.com/juju/juju/cmd/juju/backups" 15 "github.com/juju/juju/testing" 16 ) 17 18 type listSuite struct { 19 BaseBackupsSuite 20 subcommand *backups.ListCommand 21 } 22 23 var _ = gc.Suite(&listSuite{}) 24 25 func (s *listSuite) SetUpTest(c *gc.C) { 26 s.BaseBackupsSuite.SetUpTest(c) 27 s.subcommand = &backups.ListCommand{} 28 } 29 30 func (s *listSuite) TestHelp(c *gc.C) { 31 ctx, err := testing.RunCommand(c, s.command, "list", "--help") 32 c.Assert(err, jc.ErrorIsNil) 33 34 info := s.subcommand.Info() 35 expected := "(?sm)usage: juju backups list [options]$.*" 36 expected = strings.Replace(expected, "[", `\[`, -1) 37 c.Check(testing.Stdout(ctx), gc.Matches, expected) 38 expected = "(?sm).*^purpose: " + info.Purpose + "$.*" 39 c.Check(testing.Stdout(ctx), gc.Matches, expected) 40 expected = "(?sm).*^" + info.Doc + "$.*" 41 c.Check(testing.Stdout(ctx), gc.Matches, expected) 42 } 43 44 func (s *listSuite) TestOkay(c *gc.C) { 45 s.setSuccess() 46 ctx := cmdtesting.Context(c) 47 err := s.subcommand.Run(ctx) 48 c.Check(err, jc.ErrorIsNil) 49 50 out := MetaResultString 51 s.checkStd(c, ctx, out, "") 52 } 53 54 func (s *listSuite) TestBrief(c *gc.C) { 55 s.setSuccess() 56 s.subcommand.Brief = true 57 ctx := cmdtesting.Context(c) 58 err := s.subcommand.Run(ctx) 59 c.Check(err, jc.ErrorIsNil) 60 61 out := s.metaresult.ID + "\n" 62 s.checkStd(c, ctx, out, "") 63 } 64 65 func (s *listSuite) TestError(c *gc.C) { 66 s.setFailure("failed!") 67 ctx := cmdtesting.Context(c) 68 err := s.subcommand.Run(ctx) 69 70 c.Check(errors.Cause(err), gc.ErrorMatches, "failed!") 71 }