github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/backups/remove_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 removeSuite struct { 19 BaseBackupsSuite 20 subcommand *backups.RemoveCommand 21 } 22 23 var _ = gc.Suite(&removeSuite{}) 24 25 func (s *removeSuite) SetUpTest(c *gc.C) { 26 s.BaseBackupsSuite.SetUpTest(c) 27 s.subcommand = &backups.RemoveCommand{} 28 } 29 30 func (s *removeSuite) TestHelp(c *gc.C) { 31 ctx, err := testing.RunCommand(c, s.command, "remove", "--help") 32 c.Assert(err, jc.ErrorIsNil) 33 34 info := s.subcommand.Info() 35 expected := "(?sm)usage: juju backups remove [options] " + info.Args + "$.*" 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 *removeSuite) TestOkay(c *gc.C) { 45 s.setSuccess() 46 s.subcommand.ID = "spam" 47 ctx := cmdtesting.Context(c) 48 err := s.subcommand.Run(ctx) 49 c.Check(err, jc.ErrorIsNil) 50 51 out := "successfully removed: spam\n" 52 s.checkStd(c, ctx, out, "") 53 } 54 55 func (s *removeSuite) TestError(c *gc.C) { 56 s.setFailure("failed!") 57 ctx := cmdtesting.Context(c) 58 err := s.subcommand.Run(ctx) 59 60 c.Check(errors.Cause(err), gc.ErrorMatches, "failed!") 61 }