github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/service/expose_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package service 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 "github.com/juju/juju/cmd/juju/common" 13 jujutesting "github.com/juju/juju/juju/testing" 14 "github.com/juju/juju/rpc" 15 "github.com/juju/juju/testcharms" 16 "github.com/juju/juju/testing" 17 ) 18 19 type ExposeSuite struct { 20 jujutesting.RepoSuite 21 common.CmdBlockHelper 22 } 23 24 func (s *ExposeSuite) SetUpTest(c *gc.C) { 25 s.RepoSuite.SetUpTest(c) 26 s.CmdBlockHelper = common.NewCmdBlockHelper(s.APIState) 27 c.Assert(s.CmdBlockHelper, gc.NotNil) 28 s.AddCleanup(func(*gc.C) { s.CmdBlockHelper.Close() }) 29 } 30 31 var _ = gc.Suite(&ExposeSuite{}) 32 33 func runExpose(c *gc.C, args ...string) error { 34 _, err := testing.RunCommand(c, NewExposeCommand(), args...) 35 return err 36 } 37 38 func (s *ExposeSuite) assertExposed(c *gc.C, service string) { 39 svc, err := s.State.Service(service) 40 c.Assert(err, jc.ErrorIsNil) 41 exposed := svc.IsExposed() 42 c.Assert(exposed, jc.IsTrue) 43 } 44 45 func (s *ExposeSuite) TestExpose(c *gc.C) { 46 ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") 47 err := runDeploy(c, ch, "some-service-name", "--series", "trusty") 48 c.Assert(err, jc.ErrorIsNil) 49 curl := charm.MustParseURL("local:trusty/dummy-1") 50 s.AssertService(c, "some-service-name", curl, 1, 0) 51 52 err = runExpose(c, "some-service-name") 53 c.Assert(err, jc.ErrorIsNil) 54 s.assertExposed(c, "some-service-name") 55 56 err = runExpose(c, "nonexistent-service") 57 c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{ 58 Message: `service "nonexistent-service" not found`, 59 Code: "not found", 60 }) 61 } 62 63 func (s *ExposeSuite) TestBlockExpose(c *gc.C) { 64 ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") 65 err := runDeploy(c, ch, "some-service-name", "--series", "trusty") 66 c.Assert(err, jc.ErrorIsNil) 67 curl := charm.MustParseURL("local:trusty/dummy-1") 68 s.AssertService(c, "some-service-name", curl, 1, 0) 69 70 // Block operation 71 s.BlockAllChanges(c, "TestBlockExpose") 72 73 err = runExpose(c, "some-service-name") 74 s.AssertBlocked(c, err, ".*TestBlockExpose.*") 75 }