github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cmd/juju/backups/backups_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  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/testing"
    13  )
    14  
    15  var expectedSubCommmandNames = []string{
    16  	"create",
    17  	"download",
    18  	"help",
    19  	"info",
    20  	"list",
    21  	"remove",
    22  	"restore",
    23  	"upload",
    24  }
    25  
    26  type backupsSuite struct {
    27  	BaseBackupsSuite
    28  }
    29  
    30  var _ = gc.Suite(&backupsSuite{})
    31  
    32  func (s *backupsSuite) checkHelpCommands(c *gc.C) {
    33  	ctx, err := testing.RunCommand(c, s.command, "--help")
    34  	c.Assert(err, jc.ErrorIsNil)
    35  
    36  	// Check that we have registered all the sub commands by
    37  	// inspecting the help output.
    38  	var namesFound []string
    39  	commandHelp := strings.SplitAfter(testing.Stdout(ctx), "commands:")[1]
    40  	commandHelp = strings.TrimSpace(commandHelp)
    41  	for _, line := range strings.Split(commandHelp, "\n") {
    42  		name := strings.TrimSpace(strings.Split(line, " - ")[0])
    43  		namesFound = append(namesFound, name)
    44  	}
    45  	c.Check(namesFound, gc.DeepEquals, expectedSubCommmandNames)
    46  }
    47  
    48  func (s *backupsSuite) TestHelp(c *gc.C) {
    49  	ctx, err := testing.RunCommand(c, s.command, "--help")
    50  	c.Assert(err, jc.ErrorIsNil)
    51  
    52  	expected := "(?s)usage: juju backups \\[options\\] <command> .+"
    53  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    54  	expected = "(?sm).*^purpose: " + s.command.Purpose + "$.*"
    55  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    56  	expected = "(?sm).*^" + s.command.Doc + "$.*"
    57  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    58  
    59  	s.checkHelpCommands(c)
    60  }