github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/expose_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  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/juju/charm.v4"
    10  
    11  	"github.com/juju/cmd"
    12  	"github.com/juju/juju/cmd/envcmd"
    13  	jujutesting "github.com/juju/juju/juju/testing"
    14  	"github.com/juju/juju/testcharms"
    15  	"github.com/juju/juju/testing"
    16  	"strings"
    17  )
    18  
    19  type ExposeSuite struct {
    20  	jujutesting.RepoSuite
    21  }
    22  
    23  var _ = gc.Suite(&ExposeSuite{})
    24  
    25  func runExpose(c *gc.C, args ...string) error {
    26  	_, err := testing.RunCommand(c, envcmd.Wrap(&ExposeCommand{}), args...)
    27  	return err
    28  }
    29  
    30  func (s *ExposeSuite) assertExposed(c *gc.C, service string) {
    31  	svc, err := s.State.Service(service)
    32  	c.Assert(err, jc.ErrorIsNil)
    33  	exposed := svc.IsExposed()
    34  	c.Assert(exposed, jc.IsTrue)
    35  }
    36  
    37  func (s *ExposeSuite) TestExpose(c *gc.C) {
    38  	testcharms.Repo.CharmArchivePath(s.SeriesPath, "dummy")
    39  	err := runDeploy(c, "local:dummy", "some-service-name")
    40  	c.Assert(err, jc.ErrorIsNil)
    41  	curl := charm.MustParseURL("local:trusty/dummy-1")
    42  	s.AssertService(c, "some-service-name", curl, 1, 0)
    43  
    44  	err = runExpose(c, "some-service-name")
    45  	c.Assert(err, jc.ErrorIsNil)
    46  	s.assertExposed(c, "some-service-name")
    47  
    48  	err = runExpose(c, "nonexistent-service")
    49  	c.Assert(err, gc.ErrorMatches, `service "nonexistent-service" not found`)
    50  }
    51  
    52  func (s *ExposeSuite) TestBlockExpose(c *gc.C) {
    53  	testcharms.Repo.CharmArchivePath(s.SeriesPath, "dummy")
    54  	err := runDeploy(c, "local:dummy", "some-service-name")
    55  	c.Assert(err, jc.ErrorIsNil)
    56  	curl := charm.MustParseURL("local:trusty/dummy-1")
    57  	s.AssertService(c, "some-service-name", curl, 1, 0)
    58  
    59  	// Block operation
    60  	s.AssertConfigParameterUpdated(c, "block-all-changes", true)
    61  
    62  	err = runExpose(c, "some-service-name")
    63  	c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error())
    64  	// msg is logged
    65  	stripped := strings.Replace(c.GetTestLog(), "\n", "", -1)
    66  	c.Check(stripped, gc.Matches, ".*To unblock changes.*")
    67  }