github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/user/disenable_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 "github.com/juju/cmd" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/cmd/juju/user" 12 "github.com/juju/juju/testing" 13 ) 14 15 type DisableUserSuite struct { 16 BaseSuite 17 mock *mockDisenableUserAPI 18 } 19 20 var _ = gc.Suite(&DisableUserSuite{}) 21 22 func (s *DisableUserSuite) SetUpTest(c *gc.C) { 23 s.BaseSuite.SetUpTest(c) 24 s.mock = &mockDisenableUserAPI{} 25 } 26 27 type disenableCommand interface { 28 cmd.Command 29 Username() string 30 } 31 32 func (s *DisableUserSuite) testInit(c *gc.C, wrappedCommand cmd.Command, command *user.DisenableUserBase) { 33 for i, test := range []struct { 34 args []string 35 errMatch string 36 user string 37 enable bool 38 }{ 39 { 40 errMatch: "no username supplied", 41 }, { 42 args: []string{"username", "password"}, 43 errMatch: `unrecognized args: \["password"\]`, 44 }, { 45 args: []string{"username"}, 46 user: "username", 47 }, 48 } { 49 c.Logf("test %d, args %v", i, test.args) 50 err := testing.InitCommand(wrappedCommand, test.args) 51 if test.errMatch == "" { 52 c.Assert(err, jc.ErrorIsNil) 53 c.Assert(command.User, gc.Equals, test.user) 54 } else { 55 c.Assert(err, gc.ErrorMatches, test.errMatch) 56 } 57 } 58 } 59 60 func (s *DisableUserSuite) TestInit(c *gc.C) { 61 wrappedCommand, command := user.NewEnableCommandForTest(nil, s.store) 62 s.testInit(c, wrappedCommand, command) 63 wrappedCommand, command = user.NewDisableCommandForTest(nil, s.store) 64 s.testInit(c, wrappedCommand, command) 65 } 66 67 func (s *DisableUserSuite) TestDisable(c *gc.C) { 68 username := "testing" 69 disableCommand, _ := user.NewDisableCommandForTest(s.mock, s.store) 70 _, err := testing.RunCommand(c, disableCommand, username) 71 c.Assert(err, jc.ErrorIsNil) 72 c.Assert(s.mock.disable, gc.Equals, username) 73 } 74 75 func (s *DisableUserSuite) TestEnable(c *gc.C) { 76 username := "testing" 77 enableCommand, _ := user.NewEnableCommandForTest(s.mock, s.store) 78 _, err := testing.RunCommand(c, enableCommand, username) 79 c.Assert(err, jc.ErrorIsNil) 80 c.Assert(s.mock.enable, gc.Equals, username) 81 } 82 83 type mockDisenableUserAPI struct { 84 enable string 85 disable string 86 } 87 88 func (m *mockDisenableUserAPI) Close() error { 89 return nil 90 } 91 92 func (m *mockDisenableUserAPI) EnableUser(username string) error { 93 m.enable = username 94 return nil 95 } 96 97 func (m *mockDisenableUserAPI) DisableUser(username string) error { 98 m.disable = username 99 return nil 100 }