github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/firewaller/application_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/core/watcher/watchertest" 13 ) 14 15 type applicationSuite struct { 16 firewallerSuite 17 18 apiApplication *firewaller.Application 19 } 20 21 var _ = gc.Suite(&applicationSuite{}) 22 23 func (s *applicationSuite) SetUpTest(c *gc.C) { 24 s.firewallerSuite.SetUpTest(c) 25 26 var err error 27 apiUnit, err := s.firewaller.Unit(s.units[0].Tag().(names.UnitTag)) 28 s.apiApplication, err = apiUnit.Application() 29 c.Assert(err, jc.ErrorIsNil) 30 } 31 32 func (s *applicationSuite) TearDownTest(c *gc.C) { 33 s.firewallerSuite.TearDownTest(c) 34 } 35 36 func (s *applicationSuite) TestName(c *gc.C) { 37 c.Assert(s.apiApplication.Name(), gc.Equals, s.application.Name()) 38 } 39 40 func (s *applicationSuite) TestTag(c *gc.C) { 41 c.Assert(s.apiApplication.Tag(), gc.Equals, names.NewApplicationTag(s.application.Name())) 42 } 43 44 func (s *applicationSuite) TestWatch(c *gc.C) { 45 s.WaitForModelWatchersIdle(c, s.Model.UUID()) 46 47 w, err := s.apiApplication.Watch() 48 c.Assert(err, jc.ErrorIsNil) 49 wc := watchertest.NewNotifyWatcherC(c, w, s.BackingState.StartSync) 50 defer wc.AssertStops() 51 52 // Initial event. 53 wc.AssertOneChange() 54 55 // Change something and check it's detected. 56 err = s.application.SetExposed() 57 c.Assert(err, jc.ErrorIsNil) 58 wc.AssertOneChange() 59 60 // Destroy the application and check it's detected. 61 err = s.application.Destroy() 62 c.Assert(err, jc.ErrorIsNil) 63 wc.AssertOneChange() 64 } 65 66 func (s *applicationSuite) TestIsExposed(c *gc.C) { 67 err := s.application.SetExposed() 68 c.Assert(err, jc.ErrorIsNil) 69 70 isExposed, err := s.apiApplication.IsExposed() 71 c.Assert(err, jc.ErrorIsNil) 72 c.Assert(isExposed, jc.IsTrue) 73 74 err = s.application.ClearExposed() 75 c.Assert(err, jc.ErrorIsNil) 76 77 isExposed, err = s.apiApplication.IsExposed() 78 c.Assert(err, jc.ErrorIsNil) 79 c.Assert(isExposed, jc.IsFalse) 80 }