github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/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/envcmd"
    11  	"github.com/juju/juju/cmd/juju/block"
    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.FakeJujuHomeSuite.SetUpTest(c)
    23  	s.mockClient = &block.MockBlockClient{}
    24  	s.PatchValue(block.ListClient, func(p *block.ListCommand) (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, envcmd.Wrap(&block.ListCommand{}))
    33  	c.Assert(err, jc.ErrorIsNil)
    34  	c.Assert(testing.Stdout(ctx), gc.Equals, `
    35  destroy-environment  =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, envcmd.Wrap(&block.ListCommand{}))
    44  	c.Assert(err, jc.ErrorIsNil)
    45  	c.Assert(testing.Stdout(ctx), gc.Equals, `
    46  destroy-environment  =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, envcmd.Wrap(&block.ListCommand{}), "--format", "yaml")
    55  	c.Assert(err, jc.ErrorIsNil)
    56  	c.Assert(testing.Stdout(ctx), gc.Equals, `
    57  - block: destroy-environment
    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, envcmd.Wrap(&block.ListCommand{}), "--format", "json")
    70  	c.Assert(err, jc.ErrorIsNil)
    71  	c.Assert(testing.Stdout(ctx), gc.Equals, `[{"block":"destroy-environment","enabled":false},{"block":"remove-object","enabled":true,"message":"Test this one"},{"block":"all-changes","enabled":false}]
    72  `)
    73  }