github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/block/list_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package block_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 10 "github.com/juju/juju/cmd/juju/block" 11 "github.com/juju/juju/cmd/modelcmd" 12 "github.com/juju/juju/state/multiwatcher" 13 "github.com/juju/juju/testing" 14 ) 15 16 type listCommandSuite struct { 17 ProtectionCommandSuite 18 mockClient *block.MockBlockClient 19 } 20 21 func (s *listCommandSuite) SetUpTest(c *gc.C) { 22 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 23 s.mockClient = &block.MockBlockClient{} 24 s.PatchValue(block.ListClient, func(_ *modelcmd.ModelCommandBase) (block.BlockListAPI, error) { 25 return s.mockClient, nil 26 }) 27 } 28 29 var _ = gc.Suite(&listCommandSuite{}) 30 31 func (s *listCommandSuite) TestListEmpty(c *gc.C) { 32 ctx, err := testing.RunCommand(c, block.NewListCommand()) 33 c.Assert(err, jc.ErrorIsNil) 34 c.Assert(testing.Stdout(ctx), gc.Equals, ` 35 destroy-model =off 36 remove-object =off 37 all-changes =off 38 `) 39 } 40 41 func (s *listCommandSuite) TestList(c *gc.C) { 42 s.mockClient.SwitchBlockOn(string(multiwatcher.BlockRemove), "Test this one") 43 ctx, err := testing.RunCommand(c, block.NewListCommand()) 44 c.Assert(err, jc.ErrorIsNil) 45 c.Assert(testing.Stdout(ctx), gc.Equals, ` 46 destroy-model =off 47 remove-object =on, Test this one 48 all-changes =off 49 `) 50 } 51 52 func (s *listCommandSuite) TestListYaml(c *gc.C) { 53 s.mockClient.SwitchBlockOn(string(multiwatcher.BlockRemove), "Test this one") 54 ctx, err := testing.RunCommand(c, block.NewListCommand(), "--format", "yaml") 55 c.Assert(err, jc.ErrorIsNil) 56 c.Assert(testing.Stdout(ctx), gc.Equals, ` 57 - block: destroy-model 58 enabled: false 59 - block: remove-object 60 enabled: true 61 message: Test this one 62 - block: all-changes 63 enabled: false 64 `[1:]) 65 } 66 67 func (s *listCommandSuite) TestListJson(c *gc.C) { 68 s.mockClient.SwitchBlockOn(string(multiwatcher.BlockRemove), "Test this one") 69 ctx, err := testing.RunCommand(c, block.NewListCommand(), "--format", "json") 70 c.Assert(err, jc.ErrorIsNil) 71 c.Assert(testing.Stdout(ctx), gc.Equals, `[{"block":"destroy-model","enabled":false},{"block":"remove-object","enabled":true,"message":"Test this one"},{"block":"all-changes","enabled":false}] 72 `) 73 }