github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/featuretests/block_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package featuretests
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/cmd/cmdtesting"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/api/block"
    14  	jujutesting "github.com/juju/juju/juju/testing"
    15  	"github.com/juju/juju/state/multiwatcher"
    16  )
    17  
    18  type blockSuite struct {
    19  	jujutesting.JujuConnSuite
    20  	blockClient *block.Client
    21  }
    22  
    23  func (s *blockSuite) SetUpTest(c *gc.C) {
    24  	s.JujuConnSuite.SetUpTest(c)
    25  	s.blockClient = block.NewClient(s.APIState)
    26  	c.Assert(s.blockClient, gc.NotNil)
    27  	s.AddCleanup(func(*gc.C) {
    28  		s.blockClient.ClientFacade.Close()
    29  	})
    30  }
    31  
    32  func (s *blockSuite) TestBlockFacadeCall(c *gc.C) {
    33  	found, err := s.blockClient.List()
    34  	c.Assert(err, jc.ErrorIsNil)
    35  	c.Assert(found, gc.HasLen, 0)
    36  }
    37  
    38  func (s *blockSuite) TestBlockedMessage(c *gc.C) {
    39  	// Block operation
    40  	s.blockClient.SwitchBlockOn(fmt.Sprintf("%v", multiwatcher.BlockChange), "TestBlockedMessage")
    41  
    42  	ctx, err := runCommand(c, "resolved", "multi-series/2")
    43  
    44  	// Whenever Juju blocks are enabled, the operations that are blocked will be expected to err
    45  	// out silently.
    46  	c.Assert(err, gc.ErrorMatches, "cmd: error out silently")
    47  	c.Assert(cmdtesting.Stdout(ctx), gc.Equals, "")
    48  	c.Assert(cmdtesting.Stderr(ctx), gc.Equals, `
    49  ERROR TestBlockedMessage (operation is blocked)
    50  
    51  All operations that change model have been disabled for the current model.
    52  To enable changes, run
    53  
    54      juju enable-command all
    55  
    56  
    57  `[1:])
    58  }