github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/application/expose_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 ExposeSuite struct { 19 jujutesting.RepoSuite 20 testing.CmdBlockHelper 21 } 22 23 func (s *ExposeSuite) 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(&ExposeSuite{}) 31 32 func runExpose(c *gc.C, args ...string) error { 33 _, err := testing.RunCommand(c, NewExposeCommand(), args...) 34 return err 35 } 36 37 func (s *ExposeSuite) assertExposed(c *gc.C, application string) { 38 svc, err := s.State.Application(application) 39 c.Assert(err, jc.ErrorIsNil) 40 exposed := svc.IsExposed() 41 c.Assert(exposed, jc.IsTrue) 42 } 43 44 func (s *ExposeSuite) TestExpose(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") 54 55 err = runExpose(c, "nonexistent-application") 56 c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{ 57 Message: `application "nonexistent-application" not found`, 58 Code: "not found", 59 }) 60 } 61 62 func (s *ExposeSuite) TestBlockExpose(c *gc.C) { 63 ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") 64 err := runDeploy(c, ch, "some-application-name", "--series", "trusty") 65 c.Assert(err, jc.ErrorIsNil) 66 curl := charm.MustParseURL("local:trusty/dummy-1") 67 s.AssertService(c, "some-application-name", curl, 1, 0) 68 69 // Block operation 70 s.BlockAllChanges(c, "TestBlockExpose") 71 72 err = runExpose(c, "some-application-name") 73 s.AssertBlocked(c, err, ".*TestBlockExpose.*") 74 }