github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cmd/juju/environment/environment_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package environment_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	"github.com/juju/utils/set"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/cmd/juju/environment"
    12  	"github.com/juju/juju/feature"
    13  	"github.com/juju/juju/juju/osenv"
    14  	// Bring in the dummy provider definition.
    15  	_ "github.com/juju/juju/provider/dummy"
    16  	"github.com/juju/juju/testing"
    17  )
    18  
    19  type EnvironmentCommandSuite struct {
    20  	testing.BaseSuite
    21  }
    22  
    23  var _ = gc.Suite(&EnvironmentCommandSuite{})
    24  
    25  var expectedCommmandNames = []string{
    26  	"destroy",
    27  	"get",
    28  	"get-constraints",
    29  	"help",
    30  	"jenv",
    31  	"retry-provisioning",
    32  	"set",
    33  	"set-constraints",
    34  	"share",
    35  	"unset",
    36  	"unshare",
    37  	"users",
    38  }
    39  
    40  func (s *EnvironmentCommandSuite) TestHelpCommands(c *gc.C) {
    41  	defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir()))
    42  
    43  	// Check that we have correctly registered all the commands
    44  	// by checking the help output.
    45  	// First check default commands, and then check commands that are
    46  	// activated by feature flags.
    47  
    48  	// Remove "share" for the first test because the feature is not
    49  	// enabled.
    50  	devFeatures := set.NewStrings("destroy", "share", "unshare", "users")
    51  
    52  	// Remove features behind dev_flag for the first test since they are not
    53  	// enabled.
    54  	cmdSet := set.NewStrings(expectedCommmandNames...).Difference(devFeatures)
    55  
    56  	// Test default commands.
    57  	c.Assert(getHelpCommandNames(c), jc.SameContents, cmdSet.Values())
    58  
    59  	// Enable development features, and test again. We should now see the
    60  	// development commands.
    61  	s.SetFeatureFlags(feature.JES)
    62  	c.Assert(getHelpCommandNames(c), jc.SameContents, expectedCommmandNames)
    63  }
    64  
    65  func getHelpCommandNames(c *gc.C) []string {
    66  	ctx, err := testing.RunCommand(c, environment.NewSuperCommand(), "--help")
    67  	c.Assert(err, jc.ErrorIsNil)
    68  	return testing.ExtractCommandsFromHelpOutput(ctx)
    69  }