github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/cmd/juju/storage/help_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package storage_test
     5  
     6  import (
     7  	"strings"
     8  
     9  	"github.com/juju/cmd"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/cmd/juju/storage"
    14  	"github.com/juju/juju/testing"
    15  )
    16  
    17  type HelpStorageSuite struct {
    18  	testing.FakeJujuHomeSuite
    19  
    20  	command *storage.Command
    21  }
    22  
    23  func (s *HelpStorageSuite) SetUpTest(c *gc.C) {
    24  	s.FakeJujuHomeSuite.SetUpTest(c)
    25  }
    26  
    27  func (s *HelpStorageSuite) TearDownTest(c *gc.C) {
    28  	s.FakeJujuHomeSuite.TearDownTest(c)
    29  }
    30  
    31  func (s *HelpStorageSuite) assertHelp(c *gc.C, expectedNames []string) {
    32  	ctx, err := testing.RunCommand(c, s.command, "--help")
    33  	c.Assert(err, jc.ErrorIsNil)
    34  
    35  	expected := "(?sm).*^purpose: " + s.command.Purpose + "$.*"
    36  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    37  	expected = "(?sm).*^" + s.command.Doc + "$.*"
    38  	c.Check(testing.Stdout(ctx), gc.Matches, expected)
    39  
    40  	s.checkHelpCommands(c, ctx, expectedNames)
    41  }
    42  
    43  func (s *HelpStorageSuite) checkHelpCommands(c *gc.C, ctx *cmd.Context, expectedNames []string) {
    44  	// Check that we have registered all the sub commands by
    45  	// inspecting the help output.
    46  	var namesFound []string
    47  	commandHelp := strings.SplitAfter(testing.Stdout(ctx), "commands:")[1]
    48  	commandHelp = strings.TrimSpace(commandHelp)
    49  	for _, line := range strings.Split(commandHelp, "\n") {
    50  		name := strings.TrimSpace(strings.Split(line, " - ")[0])
    51  		namesFound = append(namesFound, name)
    52  	}
    53  	c.Check(namesFound, gc.DeepEquals, expectedNames)
    54  }