github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/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 15 // Bring in the dummy provider definition. 16 _ "github.com/juju/juju/provider/dummy" 17 "github.com/juju/juju/testing" 18 ) 19 20 type EnvironmentCommandSuite struct { 21 testing.BaseSuite 22 } 23 24 var _ = gc.Suite(&EnvironmentCommandSuite{}) 25 26 var expectedCommmandNames = []string{ 27 "destroy", 28 "get", 29 "get-constraints", 30 "help", 31 "jenv", 32 "retry-provisioning", 33 "set", 34 "set-constraints", 35 "share", 36 "unset", 37 "unshare", 38 "users", 39 } 40 41 func (s *EnvironmentCommandSuite) TestHelpCommands(c *gc.C) { 42 defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir())) 43 44 // Check that we have correctly registered all the commands 45 // by checking the help output. 46 // First check default commands, and then check commands that are 47 // activated by feature flags. 48 49 // Remove "share" for the first test because the feature is not 50 // enabled. 51 devFeatures := set.NewStrings("destroy", "share", "unshare", "users") 52 53 // Remove features behind dev_flag for the first test since they are not 54 // enabled. 55 cmdSet := set.NewStrings(expectedCommmandNames...).Difference(devFeatures) 56 57 // Test default commands. 58 c.Assert(getHelpCommandNames(c), jc.SameContents, cmdSet.Values()) 59 60 // Enable development features, and test again. We should now see the 61 // development commands. 62 s.SetFeatureFlags(feature.JES) 63 c.Assert(getHelpCommandNames(c), jc.SameContents, expectedCommmandNames) 64 } 65 66 func getHelpCommandNames(c *gc.C) []string { 67 ctx, err := testing.RunCommand(c, environment.NewSuperCommand(), "--help") 68 c.Assert(err, jc.ErrorIsNil) 69 return testing.ExtractCommandsFromHelpOutput(ctx) 70 }