github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/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 gc "launchpad.net/gocheck" 8 9 "launchpad.net/juju-core/charm" 10 jujutesting "launchpad.net/juju-core/juju/testing" 11 "launchpad.net/juju-core/testing" 12 ) 13 14 type UnexposeSuite struct { 15 jujutesting.RepoSuite 16 } 17 18 var _ = gc.Suite(&UnexposeSuite{}) 19 20 func runUnexpose(c *gc.C, args ...string) error { 21 _, err := testing.RunCommand(c, &UnexposeCommand{}, args) 22 return err 23 } 24 25 func (s *UnexposeSuite) assertExposed(c *gc.C, service string, expected bool) { 26 svc, err := s.State.Service(service) 27 c.Assert(err, gc.IsNil) 28 actual := svc.IsExposed() 29 c.Assert(actual, gc.Equals, expected) 30 } 31 32 func (s *UnexposeSuite) TestUnexpose(c *gc.C) { 33 testing.Charms.BundlePath(s.SeriesPath, "dummy") 34 err := runDeploy(c, "local:dummy", "some-service-name") 35 c.Assert(err, gc.IsNil) 36 curl := charm.MustParseURL("local:precise/dummy-1") 37 s.AssertService(c, "some-service-name", curl, 1, 0) 38 39 err = runExpose(c, "some-service-name") 40 c.Assert(err, gc.IsNil) 41 s.assertExposed(c, "some-service-name", true) 42 43 err = runUnexpose(c, "some-service-name") 44 c.Assert(err, gc.IsNil) 45 s.assertExposed(c, "some-service-name", false) 46 47 err = runUnexpose(c, "nonexistent-service") 48 c.Assert(err, gc.ErrorMatches, `service "nonexistent-service" not found`) 49 }