github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/api"
    11  	"github.com/juju/juju/api/rsyslog"
    12  	"github.com/juju/juju/juju/testing"
    13  	"github.com/juju/juju/network"
    14  	"github.com/juju/juju/state"
    15  	statetesting "github.com/juju/juju/state/testing"
    16  	coretesting "github.com/juju/juju/testing"
    17  )
    18  
    19  type rsyslogSuite struct {
    20  	testing.JujuConnSuite
    21  
    22  	st      *api.State
    23  	machine *state.Machine
    24  	rsyslog *rsyslog.State
    25  }
    26  
    27  var _ = gc.Suite(&rsyslogSuite{})
    28  
    29  func (s *rsyslogSuite) SetUpTest(c *gc.C) {
    30  	s.JujuConnSuite.SetUpTest(c)
    31  
    32  	s.st, s.machine = s.OpenAPIAsNewMachine(c, state.JobManageEnviron)
    33  	err := s.machine.SetAddresses(network.NewAddress("0.1.2.3", network.ScopeUnknown))
    34  	c.Assert(err, jc.ErrorIsNil)
    35  
    36  	// Create the rsyslog API facade
    37  	s.rsyslog = s.st.Rsyslog()
    38  	c.Assert(s.rsyslog, gc.NotNil)
    39  }
    40  
    41  func (s *rsyslogSuite) TestGetRsyslogConfig(c *gc.C) {
    42  	err := s.APIState.Client().EnvironmentSet(map[string]interface{}{"rsyslog-ca-cert": coretesting.CACert})
    43  	c.Assert(err, jc.ErrorIsNil)
    44  
    45  	cfg, err := s.rsyslog.GetRsyslogConfig(s.machine.Tag().String())
    46  	c.Assert(err, jc.ErrorIsNil)
    47  	c.Assert(cfg, gc.NotNil)
    48  
    49  	c.Assert(cfg.CACert, gc.Equals, coretesting.CACert)
    50  	c.Assert(cfg.HostPorts, gc.HasLen, 1)
    51  	hostPort := cfg.HostPorts[0]
    52  	c.Assert(hostPort.Address.Value, gc.Equals, "0.1.2.3")
    53  
    54  	// the rsyslog port is set by the provider/dummy/environs.go
    55  	c.Assert(hostPort.Port, gc.Equals, 2345)
    56  }
    57  
    58  func (s *rsyslogSuite) TestWatchForRsyslogChanges(c *gc.C) {
    59  	w, err := s.rsyslog.WatchForRsyslogChanges(s.machine.Tag().String())
    60  	c.Assert(err, jc.ErrorIsNil)
    61  	defer statetesting.AssertStop(c, w)
    62  
    63  	wc := statetesting.NewNotifyWatcherC(c, s.BackingState, w)
    64  	// Initial event
    65  	wc.AssertOneChange()
    66  
    67  	// change the API HostPorts
    68  	newHostPorts := network.NewHostPorts(6541, "127.0.0.1")
    69  	err = s.State.SetAPIHostPorts([][]network.HostPort{newHostPorts})
    70  	c.Assert(err, jc.ErrorIsNil)
    71  
    72  	// assert we get notified
    73  	wc.AssertOneChange()
    74  
    75  	statetesting.AssertStop(c, w)
    76  	wc.AssertClosed()
    77  }
    78  
    79  // SetRsyslogCACert is tested in apiserver/rsyslog