github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/juju/controller/enabledestroy_test.go (about)

     1  // Copyright 2016 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/jujuclient"
    14  	"github.com/juju/juju/jujuclient/jujuclienttesting"
    15  	"github.com/juju/juju/testing"
    16  )
    17  
    18  type enableDestroyControllerSuite struct {
    19  	baseControllerSuite
    20  	api   *fakeRemoveBlocksAPI
    21  	store *jujuclienttesting.MemStore
    22  }
    23  
    24  var _ = gc.Suite(&enableDestroyControllerSuite{})
    25  
    26  func (s *enableDestroyControllerSuite) SetUpTest(c *gc.C) {
    27  	s.baseControllerSuite.SetUpTest(c)
    28  
    29  	s.api = &fakeRemoveBlocksAPI{}
    30  	s.store = jujuclienttesting.NewMemStore()
    31  	s.store.CurrentControllerName = "fake"
    32  	s.store.Controllers["fake"] = jujuclient.ControllerDetails{}
    33  }
    34  
    35  func (s *enableDestroyControllerSuite) newCommand() cmd.Command {
    36  	return controller.NewEnableDestroyControllerCommandForTest(s.api, s.store)
    37  }
    38  
    39  func (s *enableDestroyControllerSuite) TestRemove(c *gc.C) {
    40  	_, err := testing.RunCommand(c, s.newCommand())
    41  	c.Assert(err, jc.ErrorIsNil)
    42  	c.Assert(s.api.called, jc.IsTrue)
    43  }
    44  
    45  func (s *enableDestroyControllerSuite) TestUnrecognizedArg(c *gc.C) {
    46  	_, err := testing.RunCommand(c, s.newCommand(), "whoops")
    47  	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["whoops"\]`)
    48  	c.Assert(s.api.called, jc.IsFalse)
    49  }
    50  
    51  func (s *enableDestroyControllerSuite) TestEnvironmentsError(c *gc.C) {
    52  	s.api.err = common.ErrPerm
    53  	_, err := testing.RunCommand(c, s.newCommand())
    54  	c.Assert(err, gc.ErrorMatches, "permission denied")
    55  }
    56  
    57  type fakeRemoveBlocksAPI struct {
    58  	err    error
    59  	called bool
    60  }
    61  
    62  func (f *fakeRemoveBlocksAPI) Close() error {
    63  	return nil
    64  }
    65  
    66  func (f *fakeRemoveBlocksAPI) RemoveBlocks() error {
    67  	f.called = true
    68  	return f.err
    69  }