github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/unexpose_test.go (about)

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