github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/state/api/rsyslog/rsyslog_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package rsyslog_test 5 6 import ( 7 gc "launchpad.net/gocheck" 8 9 "github.com/juju/juju/juju/testing" 10 "github.com/juju/juju/network" 11 "github.com/juju/juju/state" 12 "github.com/juju/juju/state/api" 13 "github.com/juju/juju/state/api/rsyslog" 14 statetesting "github.com/juju/juju/state/testing" 15 coretesting "github.com/juju/juju/testing" 16 ) 17 18 type rsyslogSuite struct { 19 testing.JujuConnSuite 20 21 st *api.State 22 machine *state.Machine 23 rsyslog *rsyslog.State 24 } 25 26 var _ = gc.Suite(&rsyslogSuite{}) 27 28 func (s *rsyslogSuite) SetUpTest(c *gc.C) { 29 s.JujuConnSuite.SetUpTest(c) 30 31 s.st, s.machine = s.OpenAPIAsNewMachine(c, state.JobManageEnviron) 32 err := s.machine.SetAddresses(network.NewAddress("0.1.2.3", network.ScopeUnknown)) 33 c.Assert(err, gc.IsNil) 34 35 // Create the rsyslog API facade 36 s.rsyslog = s.st.Rsyslog() 37 c.Assert(s.rsyslog, gc.NotNil) 38 } 39 40 func (s *rsyslogSuite) TestGetRsyslogConfig(c *gc.C) { 41 err := s.APIState.Client().EnvironmentSet(map[string]interface{}{"rsyslog-ca-cert": coretesting.CACert}) 42 c.Assert(err, gc.IsNil) 43 44 cfg, err := s.rsyslog.GetRsyslogConfig(s.machine.Tag()) 45 c.Assert(err, gc.IsNil) 46 c.Assert(cfg, gc.NotNil) 47 48 c.Assert(cfg.CACert, gc.Equals, coretesting.CACert) 49 c.Assert(cfg.HostPorts, gc.HasLen, 1) 50 hostPort := cfg.HostPorts[0] 51 c.Assert(hostPort.Address.Value, gc.Equals, "0.1.2.3") 52 53 // the rsyslog port is set by the provider/dummy/environs.go 54 c.Assert(hostPort.Port, gc.Equals, 2345) 55 } 56 57 func (s *rsyslogSuite) TestWatchForRsyslogChanges(c *gc.C) { 58 w, err := s.rsyslog.WatchForRsyslogChanges(s.machine.Tag()) 59 c.Assert(err, gc.IsNil) 60 defer statetesting.AssertStop(c, w) 61 62 wc := statetesting.NewNotifyWatcherC(c, s.BackingState, w) 63 // Initial event 64 wc.AssertOneChange() 65 66 // change the API HostPorts 67 newHostPorts := network.AddressesWithPort(network.NewAddresses("127.0.0.1"), 6541) 68 err = s.State.SetAPIHostPorts([][]network.HostPort{newHostPorts}) 69 c.Assert(err, gc.IsNil) 70 71 // assert we get notified 72 wc.AssertOneChange() 73 74 statetesting.AssertStop(c, w) 75 wc.AssertClosed() 76 } 77 78 // SetRsyslogCACert is tested in state/apiserver/rsyslog