github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/cmd/juju/user_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package main
     5  
     6  import (
     7  	"strings"
     8  
     9  	gc "launchpad.net/gocheck"
    10  
    11  	coretesting "github.com/juju/juju/testing"
    12  )
    13  
    14  type UserCommandSuite struct {
    15  	coretesting.BaseSuite
    16  }
    17  
    18  var _ = gc.Suite(&UserCommandSuite{})
    19  
    20  var expectedUserCommmandNames = []string{
    21  	"add",
    22  	"help",
    23  }
    24  
    25  func (s *UserCommandSuite) TestHelp(c *gc.C) {
    26  	// Check the help output
    27  	ctx, err := coretesting.RunCommand(c, NewUserCommand(), "--help")
    28  	c.Assert(err, gc.IsNil)
    29  	c.Assert(coretesting.Stdout(ctx), gc.Matches,
    30  		"(?s)usage: user <command> .+"+
    31  			userCommandPurpose+".+"+
    32  			userCommandDoc+".+")
    33  
    34  	// Check that we have registered all the sub commands by
    35  	// inspecting the help output.
    36  	var namesFound []string
    37  	commandHelp := strings.SplitAfter(coretesting.Stdout(ctx), "commands:")[1]
    38  	commandHelp = strings.TrimSpace(commandHelp)
    39  	for _, line := range strings.Split(commandHelp, "\n") {
    40  		namesFound = append(namesFound, strings.TrimSpace(strings.Split(line, " - ")[0]))
    41  	}
    42  	c.Assert(namesFound, gc.DeepEquals, expectedUserCommmandNames)
    43  }