github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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  	"upload",
    23  }
    24  
    25  type backupsSuite struct {
    26  	BaseBackupsSuite
    27  }
    28  
    29  var _ = gc.Suite(&backupsSuite{})
    30  
    31  func (s *backupsSuite) checkHelpCommands(c *gc.C) {
    32  	ctx, err := testing.RunCommand(c, s.command, "--help")
    33  	c.Assert(err, jc.ErrorIsNil)
    34  
    35  	// Check that we have registered all the sub commands by
    36  	// inspecting the help output.
    37  	var namesFound []string
    38  	commandHelp := strings.SplitAfter(testing.Stdout(ctx), "commands:")[1]
    39  	commandHelp = strings.TrimSpace(commandHelp)
    40  	for _, line := range strings.Split(commandHelp, "\n") {
    41  		name := strings.TrimSpace(strings.Split(line, " - ")[0])
    42  		namesFound = append(namesFound, name)
    43  	}
    44  	c.Check(namesFound, gc.DeepEquals, expectedSubCommmandNames)
    45  }
    46  
    47  func (s *backupsSuite) TestHelp(c *gc.C) {
    48  	ctx, err := testing.RunCommand(c, s.command, "--help")
    49  	c.Assert(err, jc.ErrorIsNil)
    50  
    51  	expected := "(?s)usage: juju backups <command> .+"
    52  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    53  	expected = "(?sm).*^purpose: " + s.command.Purpose + "$.*"
    54  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    55  	expected = "(?sm).*^" + s.command.Doc + "$.*"
    56  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    57  
    58  	s.checkHelpCommands(c)
    59  }