github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/application/unexpose_test.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package application
     5  
     6  import (
     7  	"github.com/juju/cmd/cmdtesting"
     8  	"github.com/juju/errors"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  	"gopkg.in/juju/charm.v6"
    12  
    13  	jujutesting "github.com/juju/juju/juju/testing"
    14  	"github.com/juju/juju/rpc"
    15  	"github.com/juju/juju/testcharms"
    16  	"github.com/juju/juju/testing"
    17  )
    18  
    19  type UnexposeSuite struct {
    20  	jujutesting.RepoSuite
    21  	testing.CmdBlockHelper
    22  }
    23  
    24  func (s *UnexposeSuite) SetUpTest(c *gc.C) {
    25  	s.RepoSuite.SetUpTest(c)
    26  	s.CmdBlockHelper = testing.NewCmdBlockHelper(s.APIState)
    27  	c.Assert(s.CmdBlockHelper, gc.NotNil)
    28  	s.AddCleanup(func(*gc.C) { s.CmdBlockHelper.Close() })
    29  }
    30  
    31  var _ = gc.Suite(&UnexposeSuite{})
    32  
    33  func runUnexpose(c *gc.C, args ...string) error {
    34  	_, err := cmdtesting.RunCommand(c, NewUnexposeCommand(), args...)
    35  	return err
    36  }
    37  
    38  func (s *UnexposeSuite) assertExposed(c *gc.C, application string, expected bool) {
    39  	svc, err := s.State.Application(application)
    40  	c.Assert(err, jc.ErrorIsNil)
    41  	actual := svc.IsExposed()
    42  	c.Assert(actual, gc.Equals, expected)
    43  }
    44  
    45  func (s *UnexposeSuite) TestUnexpose(c *gc.C) {
    46  	ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "multi-series")
    47  	err := runDeploy(c, ch, "some-application-name", "--series", "trusty")
    48  
    49  	c.Assert(err, jc.ErrorIsNil)
    50  	curl := charm.MustParseURL("local:trusty/multi-series-1")
    51  	s.AssertApplication(c, "some-application-name", curl, 1, 0)
    52  
    53  	err = runExpose(c, "some-application-name")
    54  	c.Assert(err, jc.ErrorIsNil)
    55  	s.assertExposed(c, "some-application-name", true)
    56  
    57  	err = runUnexpose(c, "some-application-name")
    58  	c.Assert(err, jc.ErrorIsNil)
    59  	s.assertExposed(c, "some-application-name", false)
    60  
    61  	err = runUnexpose(c, "nonexistent-application")
    62  	c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
    63  		Message: `application "nonexistent-application" not found`,
    64  		Code:    "not found",
    65  	})
    66  }
    67  
    68  func (s *UnexposeSuite) TestBlockUnexpose(c *gc.C) {
    69  	ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "multi-series")
    70  	err := runDeploy(c, ch, "some-application-name", "--series", "trusty")
    71  
    72  	c.Assert(err, jc.ErrorIsNil)
    73  	curl := charm.MustParseURL("local:trusty/multi-series-1")
    74  	s.AssertApplication(c, "some-application-name", curl, 1, 0)
    75  
    76  	// Block operation
    77  	s.BlockAllChanges(c, "TestBlockUnexpose")
    78  	err = runExpose(c, "some-application-name")
    79  	s.AssertBlocked(c, err, ".*TestBlockUnexpose.*")
    80  }