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