github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/model/unset_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package model_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/model"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type UnsetSuite struct {
    17  	fakeEnvSuite
    18  }
    19  
    20  var _ = gc.Suite(&UnsetSuite{})
    21  
    22  func (s *UnsetSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
    23  	command := model.NewUnsetCommandForTest(s.fake)
    24  	return testing.RunCommand(c, command, args...)
    25  }
    26  
    27  func (s *UnsetSuite) TestInit(c *gc.C) {
    28  	unsetCmd := model.NewUnsetCommandForTest(s.fake)
    29  	// Only empty is a problem.
    30  	err := testing.InitCommand(unsetCmd, []string{})
    31  	c.Assert(err, gc.ErrorMatches, "no keys specified")
    32  	// Everything else is fine.
    33  	err = testing.InitCommand(unsetCmd, []string{"something", "weird"})
    34  	c.Assert(err, jc.ErrorIsNil)
    35  }
    36  
    37  func (s *UnsetSuite) TestPassesValues(c *gc.C) {
    38  	_, err := s.run(c, "special", "running")
    39  	c.Assert(err, jc.ErrorIsNil)
    40  	c.Assert(s.fake.keys, jc.DeepEquals, []string{"special", "running"})
    41  }
    42  
    43  func (s *UnsetSuite) TestUnsettingKnownValue(c *gc.C) {
    44  	_, err := s.run(c, "unknown")
    45  	c.Assert(err, jc.ErrorIsNil)
    46  	c.Assert(s.fake.keys, jc.DeepEquals, []string{"unknown"})
    47  	// Command succeeds, but warning logged.
    48  	expected := `key "unknown" is not defined in the current model configuration: possible misspelling`
    49  	c.Check(c.GetTestLog(), jc.Contains, expected)
    50  }
    51  
    52  func (s *UnsetSuite) TestBlockedError(c *gc.C) {
    53  	s.fake.err = common.OperationBlockedError("TestBlockedError")
    54  	_, err := s.run(c, "special")
    55  	c.Assert(err, gc.Equals, cmd.ErrSilent)
    56  	// msg is logged
    57  	c.Check(c.GetTestLog(), jc.Contains, "TestBlockedError")
    58  }