~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/uniter/state_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package uniter_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
        apitesting "github.com/juju/juju/api/testing"
 
12
        "github.com/juju/juju/apiserver/params"
 
13
        "github.com/juju/juju/network"
 
14
)
 
15
 
 
16
type stateSuite struct {
 
17
        uniterSuite
 
18
        *apitesting.APIAddresserTests
 
19
        *apitesting.ModelWatcherTests
 
20
}
 
21
 
 
22
var _ = gc.Suite(&stateSuite{})
 
23
 
 
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)
 
28
}
 
29
 
 
30
func (s *stateSuite) TestProviderType(c *gc.C) {
 
31
        cfg, err := s.State.ModelConfig()
 
32
        c.Assert(err, jc.ErrorIsNil)
 
33
 
 
34
        providerType, err := s.uniter.ProviderType()
 
35
        c.Assert(err, jc.ErrorIsNil)
 
36
        c.Assert(providerType, gc.DeepEquals, cfg.Type())
 
37
}
 
38
 
 
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)
 
47
 
 
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)
 
53
 
 
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)
 
63
 
 
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()},
 
71
        })
 
72
}