github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/user/user_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package user_test 5 6 import ( 7 "os" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/cmd/juju/user" 13 "github.com/juju/juju/environs/configstore" 14 "github.com/juju/juju/juju/osenv" 15 "github.com/juju/juju/testing" 16 ) 17 18 type UserCommandSuite struct { 19 testing.BaseSuite 20 } 21 22 var _ = gc.Suite(&UserCommandSuite{}) 23 24 var expectedUserCommmandNames = []string{ 25 "add", 26 "change-password", 27 "disable", 28 "enable", 29 "help", 30 "info", 31 "list", 32 } 33 34 func (s *UserCommandSuite) TestHelp(c *gc.C) { 35 // Check the help output 36 ctx, err := testing.RunCommand(c, user.NewSuperCommand(), "--help") 37 c.Assert(err, jc.ErrorIsNil) 38 namesFound := testing.ExtractCommandsFromHelpOutput(ctx) 39 c.Assert(namesFound, gc.DeepEquals, expectedUserCommmandNames) 40 } 41 42 type BaseSuite struct { 43 testing.BaseSuite 44 } 45 46 func (s *BaseSuite) SetUpTest(c *gc.C) { 47 s.BaseSuite.SetUpTest(c) 48 memstore := configstore.NewMem() 49 s.PatchValue(&configstore.Default, func() (configstore.Storage, error) { 50 return memstore, nil 51 }) 52 os.Setenv(osenv.JujuEnvEnvKey, "testing") 53 info := memstore.CreateInfo("testing") 54 info.SetBootstrapConfig(map[string]interface{}{"random": "extra data"}) 55 info.SetAPIEndpoint(configstore.APIEndpoint{ 56 Addresses: []string{"127.0.0.1:12345"}, 57 Hostnames: []string{"localhost:12345"}, 58 CACert: testing.CACert, 59 EnvironUUID: "env-uuid", 60 }) 61 info.SetAPICredentials(configstore.APICredentials{ 62 User: "user-test", 63 Password: "password", 64 }) 65 err := info.Write() 66 c.Assert(err, jc.ErrorIsNil) 67 s.PatchValue(user.ReadPassword, func() (string, error) { 68 return "sekrit", nil 69 }) 70 }