forked from UbuntuEvangelist/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
networks_test.go
68 lines (58 loc) · 1.96 KB
/
networks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/state"
)
type NetworkSuite struct {
ConnSuite
machine *state.Machine
network *state.Network
vlan *state.Network
}
var _ = gc.Suite(&NetworkSuite{})
func (s *NetworkSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
var err error
s.machine, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
s.network, err = s.State.AddNetwork(state.NetworkInfo{"net1", "net1", "0.1.2.3/24", 0})
c.Assert(err, jc.ErrorIsNil)
s.vlan, err = s.State.AddNetwork(state.NetworkInfo{"vlan", "vlan", "0.1.2.3/30", 42})
c.Assert(err, jc.ErrorIsNil)
}
func (s *NetworkSuite) TestGetterMethods(c *gc.C) {
c.Assert(s.network.Name(), gc.Equals, "net1")
c.Assert(string(s.network.ProviderId()), gc.Equals, "net1")
c.Assert(s.network.Tag().String(), gc.Equals, "network-net1")
c.Assert(s.network.CIDR(), gc.Equals, "0.1.2.3/24")
c.Assert(s.network.VLANTag(), gc.Equals, 0)
c.Assert(s.vlan.VLANTag(), gc.Equals, 42)
c.Assert(s.network.IsVLAN(), jc.IsFalse)
c.Assert(s.vlan.IsVLAN(), jc.IsTrue)
}
func (s *NetworkSuite) TestInterfaces(c *gc.C) {
ifaces, err := s.network.Interfaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ifaces, gc.HasLen, 0)
iface0, err := s.machine.AddNetworkInterface(state.NetworkInterfaceInfo{
MACAddress: "aa:bb:cc:dd:ee:f0",
InterfaceName: "eth0",
NetworkName: "net1",
IsVirtual: false,
})
c.Assert(err, jc.ErrorIsNil)
iface1, err := s.machine.AddNetworkInterface(state.NetworkInterfaceInfo{
MACAddress: "aa:bb:cc:dd:ee:f1",
InterfaceName: "eth1",
NetworkName: "net1",
IsVirtual: false,
})
c.Assert(err, jc.ErrorIsNil)
ifaces, err = s.network.Interfaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ifaces, gc.HasLen, 2)
c.Assert(ifaces, jc.DeepEquals, []*state.NetworkInterface{iface0, iface1})
}