github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/controller/removeblocks_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package controller_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/apiserver/common" 12 "github.com/juju/juju/cmd/juju/controller" 13 "github.com/juju/juju/cmd/modelcmd" 14 "github.com/juju/juju/jujuclient" 15 "github.com/juju/juju/jujuclient/jujuclienttesting" 16 "github.com/juju/juju/testing" 17 ) 18 19 type removeBlocksSuite struct { 20 baseControllerSuite 21 api *fakeRemoveBlocksAPI 22 store *jujuclienttesting.MemStore 23 } 24 25 var _ = gc.Suite(&removeBlocksSuite{}) 26 27 func (s *removeBlocksSuite) SetUpTest(c *gc.C) { 28 s.baseControllerSuite.SetUpTest(c) 29 30 err := modelcmd.WriteCurrentController("fake") 31 c.Assert(err, jc.ErrorIsNil) 32 33 s.api = &fakeRemoveBlocksAPI{} 34 s.store = jujuclienttesting.NewMemStore() 35 s.store.Controllers["fake"] = jujuclient.ControllerDetails{} 36 } 37 38 func (s *removeBlocksSuite) newCommand() cmd.Command { 39 return controller.NewRemoveBlocksCommandForTest(s.api, s.store) 40 } 41 42 func (s *removeBlocksSuite) TestRemove(c *gc.C) { 43 _, err := testing.RunCommand(c, s.newCommand()) 44 c.Assert(err, jc.ErrorIsNil) 45 c.Assert(s.api.called, jc.IsTrue) 46 } 47 48 func (s *removeBlocksSuite) TestUnrecognizedArg(c *gc.C) { 49 _, err := testing.RunCommand(c, s.newCommand(), "whoops") 50 c.Assert(err, gc.ErrorMatches, `unrecognized args: \["whoops"\]`) 51 c.Assert(s.api.called, jc.IsFalse) 52 } 53 54 func (s *removeBlocksSuite) TestEnvironmentsError(c *gc.C) { 55 s.api.err = common.ErrPerm 56 _, err := testing.RunCommand(c, s.newCommand()) 57 c.Assert(err, gc.ErrorMatches, "cannot remove blocks: permission denied") 58 } 59 60 type fakeRemoveBlocksAPI struct { 61 err error 62 called bool 63 } 64 65 func (f *fakeRemoveBlocksAPI) Close() error { 66 return nil 67 } 68 69 func (f *fakeRemoveBlocksAPI) RemoveBlocks() error { 70 f.called = true 71 return f.err 72 }