github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/api/firewaller/service_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package firewaller_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/juju/names.v2" 10 11 "github.com/juju/juju/api/firewaller" 12 "github.com/juju/juju/apiserver/params" 13 "github.com/juju/juju/watcher/watchertest" 14 ) 15 16 type serviceSuite struct { 17 firewallerSuite 18 19 apiApplication *firewaller.Application 20 } 21 22 var _ = gc.Suite(&serviceSuite{}) 23 24 func (s *serviceSuite) SetUpTest(c *gc.C) { 25 s.firewallerSuite.SetUpTest(c) 26 27 var err error 28 apiUnit, err := s.firewaller.Unit(s.units[0].Tag().(names.UnitTag)) 29 s.apiApplication, err = apiUnit.Application() 30 c.Assert(err, jc.ErrorIsNil) 31 } 32 33 func (s *serviceSuite) TearDownTest(c *gc.C) { 34 s.firewallerSuite.TearDownTest(c) 35 } 36 37 func (s *serviceSuite) TestName(c *gc.C) { 38 c.Assert(s.apiApplication.Name(), gc.Equals, s.application.Name()) 39 } 40 41 func (s *serviceSuite) TestTag(c *gc.C) { 42 c.Assert(s.apiApplication.Tag(), gc.Equals, names.NewApplicationTag(s.application.Name())) 43 } 44 45 func (s *serviceSuite) TestWatch(c *gc.C) { 46 c.Assert(s.apiApplication.Life(), gc.Equals, params.Alive) 47 48 w, err := s.apiApplication.Watch() 49 c.Assert(err, jc.ErrorIsNil) 50 wc := watchertest.NewNotifyWatcherC(c, w, s.BackingState.StartSync) 51 defer wc.AssertStops() 52 53 // Initial event. 54 wc.AssertOneChange() 55 56 // Change something and check it's detected. 57 err = s.application.SetExposed() 58 c.Assert(err, jc.ErrorIsNil) 59 wc.AssertOneChange() 60 61 // Destroy the service and check it's detected. 62 err = s.application.Destroy() 63 c.Assert(err, jc.ErrorIsNil) 64 wc.AssertOneChange() 65 } 66 67 func (s *serviceSuite) TestRefresh(c *gc.C) { 68 c.Assert(s.apiApplication.Life(), gc.Equals, params.Alive) 69 70 err := s.application.Destroy() 71 c.Assert(err, jc.ErrorIsNil) 72 c.Assert(s.apiApplication.Life(), gc.Equals, params.Alive) 73 74 err = s.apiApplication.Refresh() 75 c.Assert(err, jc.ErrorIsNil) 76 c.Assert(s.apiApplication.Life(), gc.Equals, params.Dying) 77 } 78 79 func (s *serviceSuite) TestIsExposed(c *gc.C) { 80 err := s.application.SetExposed() 81 c.Assert(err, jc.ErrorIsNil) 82 83 isExposed, err := s.apiApplication.IsExposed() 84 c.Assert(err, jc.ErrorIsNil) 85 c.Assert(isExposed, jc.IsTrue) 86 87 err = s.application.ClearExposed() 88 c.Assert(err, jc.ErrorIsNil) 89 90 isExposed, err = s.apiApplication.IsExposed() 91 c.Assert(err, jc.ErrorIsNil) 92 c.Assert(isExposed, jc.IsFalse) 93 }