1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
jc "github.com/juju/testing/checkers"
9
"gopkg.in/juju/names.v2"
11
apitesting "github.com/juju/juju/api/testing"
12
"github.com/juju/juju/apiserver/params"
13
"github.com/juju/juju/network"
16
type stateSuite struct {
18
*apitesting.APIAddresserTests
19
*apitesting.ModelWatcherTests
22
var _ = gc.Suite(&stateSuite{})
24
func (s *stateSuite) SetUpTest(c *gc.C) {
25
s.uniterSuite.SetUpTest(c)
26
s.APIAddresserTests = apitesting.NewAPIAddresserTests(s.uniter, s.BackingState)
27
s.ModelWatcherTests = apitesting.NewModelWatcherTests(s.uniter, s.BackingState, apitesting.NoSecrets)
30
func (s *stateSuite) TestProviderType(c *gc.C) {
31
cfg, err := s.State.ModelConfig()
32
c.Assert(err, jc.ErrorIsNil)
34
providerType, err := s.uniter.ProviderType()
35
c.Assert(err, jc.ErrorIsNil)
36
c.Assert(providerType, gc.DeepEquals, cfg.Type())
39
func (s *stateSuite) TestAllMachinePorts(c *gc.C) {
40
// Verify no ports are opened yet on the machine or unit.
41
machinePorts, err := s.wordpressMachine.AllPorts()
42
c.Assert(err, jc.ErrorIsNil)
43
c.Assert(machinePorts, gc.HasLen, 0)
44
unitPorts, err := s.wordpressUnit.OpenedPorts()
45
c.Assert(err, jc.ErrorIsNil)
46
c.Assert(unitPorts, gc.HasLen, 0)
48
// Add another wordpress unit on the same machine.
49
wordpressUnit1, err := s.wordpressService.AddUnit()
50
c.Assert(err, jc.ErrorIsNil)
51
err = wordpressUnit1.AssignToMachine(s.wordpressMachine)
52
c.Assert(err, jc.ErrorIsNil)
54
// Open some ports on both units.
55
err = s.wordpressUnit.OpenPorts("tcp", 100, 200)
56
c.Assert(err, jc.ErrorIsNil)
57
err = s.wordpressUnit.OpenPorts("udp", 10, 20)
58
c.Assert(err, jc.ErrorIsNil)
59
err = wordpressUnit1.OpenPorts("tcp", 201, 250)
60
c.Assert(err, jc.ErrorIsNil)
61
err = wordpressUnit1.OpenPorts("udp", 1, 8)
62
c.Assert(err, jc.ErrorIsNil)
64
portsMap, err := s.uniter.AllMachinePorts(s.wordpressMachine.Tag().(names.MachineTag))
65
c.Assert(err, jc.ErrorIsNil)
66
c.Assert(portsMap, jc.DeepEquals, map[network.PortRange]params.RelationUnit{
67
network.PortRange{100, 200, "tcp"}: {Unit: s.wordpressUnit.Tag().String()},
68
network.PortRange{10, 20, "udp"}: {Unit: s.wordpressUnit.Tag().String()},
69
network.PortRange{201, 250, "tcp"}: {Unit: wordpressUnit1.Tag().String()},
70
network.PortRange{1, 8, "udp"}: {Unit: wordpressUnit1.Tag().String()},