github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cmd/juju/commands/unexpose_test.go (about)

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