github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/backups/info_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 infoSuite struct {
    19  	BaseBackupsSuite
    20  	subcommand *backups.InfoCommand
    21  }
    22  
    23  var _ = gc.Suite(&infoSuite{})
    24  
    25  func (s *infoSuite) SetUpTest(c *gc.C) {
    26  	s.BaseBackupsSuite.SetUpTest(c)
    27  	s.subcommand = &backups.InfoCommand{}
    28  }
    29  
    30  func (s *infoSuite) TestHelp(c *gc.C) {
    31  	ctx, err := testing.RunCommand(c, s.command, "info", "--help")
    32  	c.Assert(err, jc.ErrorIsNil)
    33  
    34  	info := s.subcommand.Info()
    35  	expected := "(?sm)usage: juju backups info [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 *infoSuite) 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 *infoSuite) TestError(c *gc.C) {
    55  	s.setFailure("failed!")
    56  	ctx := cmdtesting.Context(c)
    57  	err := s.subcommand.Run(ctx)
    58  
    59  	c.Check(errors.Cause(err), gc.ErrorMatches, "failed!")
    60  }