github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/block/unblock_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package block_test 5 6 import ( 7 "strings" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/cmd/juju/block" 13 "github.com/juju/juju/testing" 14 ) 15 16 type UnblockCommandSuite struct { 17 ProtectionCommandSuite 18 mockClient *block.MockBlockClient 19 } 20 21 func (s *UnblockCommandSuite) SetUpTest(c *gc.C) { 22 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 23 s.mockClient = &block.MockBlockClient{} 24 } 25 26 var _ = gc.Suite(&UnblockCommandSuite{}) 27 28 func (s *UnblockCommandSuite) runUnblockCommand(c *gc.C, args ...string) error { 29 _, err := testing.RunCommand(c, block.NewUnblockCommandWithClient(s.mockClient), args...) 30 return err 31 } 32 33 func (s *UnblockCommandSuite) assertRunUnblock(c *gc.C, operation string) { 34 err := s.runUnblockCommand(c, operation) 35 c.Assert(err, jc.ErrorIsNil) 36 37 expectedOp := block.TypeFromOperation(strings.ToLower(operation)) 38 c.Assert(s.mockClient.BlockType, gc.DeepEquals, expectedOp) 39 } 40 41 func (s *UnblockCommandSuite) TestUnblockCmdNoOperation(c *gc.C) { 42 s.assertErrorMatches(c, s.runUnblockCommand(c), `.*must specify one of.*`) 43 } 44 45 func (s *UnblockCommandSuite) TestUnblockCmdMoreThanOneOperation(c *gc.C) { 46 s.assertErrorMatches(c, s.runUnblockCommand(c, "destroy-model", "change"), `.*can only specify block type.*`) 47 } 48 49 func (s *UnblockCommandSuite) TestUnblockCmdOperationWithSeparator(c *gc.C) { 50 s.assertErrorMatches(c, s.runUnblockCommand(c, "destroy-model|"), `.*valid argument.*`) 51 } 52 53 func (s *UnblockCommandSuite) TestUnblockCmdUnknownJujuOperation(c *gc.C) { 54 s.assertErrorMatches(c, s.runUnblockCommand(c, "add-machine"), `.*valid argument.*`) 55 } 56 57 func (s *UnblockCommandSuite) TestUnblockCmdUnknownOperation(c *gc.C) { 58 s.assertErrorMatches(c, s.runUnblockCommand(c, "blah"), `.*valid argument.*`) 59 } 60 61 func (s *UnblockCommandSuite) TestUnblockCmdValidDestroyEnvOperationUpperCase(c *gc.C) { 62 s.assertRunUnblock(c, "DESTROY-MODEL") 63 } 64 65 func (s *UnblockCommandSuite) TestUnblockCmdValidDestroyEnvOperation(c *gc.C) { 66 s.assertRunUnblock(c, "destroy-model") 67 }