-
Notifications
You must be signed in to change notification settings - Fork 23
/
linklayerdevice_test.go
120 lines (104 loc) · 3.33 KB
/
linklayerdevice_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package description
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/yaml.v2"
)
type LinkLayerDeviceSerializationSuite struct {
SliceSerializationSuite
}
var _ = gc.Suite(&LinkLayerDeviceSerializationSuite{})
func (s *LinkLayerDeviceSerializationSuite) SetUpTest(c *gc.C) {
s.SliceSerializationSuite.SetUpTest(c)
s.importName = "link-layer-devices"
s.sliceName = "link-layer-devices"
s.importFunc = func(m map[string]interface{}) (interface{}, error) {
return importLinkLayerDevices(m)
}
s.testFields = func(m map[string]interface{}) {
m["link-layer-devices"] = []interface{}{}
}
}
func (s *LinkLayerDeviceSerializationSuite) TestNewLinkLayerDevice(c *gc.C) {
args := LinkLayerDeviceArgs{
ProviderID: "magic",
MachineID: "bar",
Name: "foo",
MTU: 54,
Type: "loopback",
MACAddress: "DEADBEEF",
IsAutoStart: true,
IsUp: true,
ParentName: "bam",
VirtualPortType: "ovs",
}
device := newLinkLayerDevice(args)
c.Assert(device.ProviderID(), gc.Equals, args.ProviderID)
c.Assert(device.MachineID(), gc.Equals, args.MachineID)
c.Assert(device.Name(), gc.Equals, args.Name)
c.Assert(device.MTU(), gc.Equals, args.MTU)
c.Assert(device.Type(), gc.Equals, args.Type)
c.Assert(device.MACAddress(), gc.Equals, args.MACAddress)
c.Assert(device.IsAutoStart(), gc.Equals, args.IsAutoStart)
c.Assert(device.IsUp(), gc.Equals, args.IsUp)
c.Assert(device.ParentName(), gc.Equals, args.ParentName)
c.Assert(device.VirtualPortType(), gc.Equals, args.VirtualPortType)
}
func (s *LinkLayerDeviceSerializationSuite) TestParsingSerializedDataV1(c *gc.C) {
initial := linklayerdevices{
Version: 1,
LinkLayerDevices_: []*linklayerdevice{
newLinkLayerDevice(LinkLayerDeviceArgs{
ProviderID: "magic",
MachineID: "bar",
Name: "foo",
MTU: 54,
Type: "loopback",
MACAddress: "DEADBEEF",
IsAutoStart: true,
IsUp: true,
ParentName: "bam",
}),
newLinkLayerDevice(LinkLayerDeviceArgs{Name: "weeee"}),
},
}
bytes, err := yaml.Marshal(initial)
c.Assert(err, jc.ErrorIsNil)
var source map[string]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
devices, err := importLinkLayerDevices(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(devices, jc.DeepEquals, initial.LinkLayerDevices_)
}
func (s *LinkLayerDeviceSerializationSuite) TestParsingSerializedDataV2(c *gc.C) {
initial := linklayerdevices{
Version: 2,
LinkLayerDevices_: []*linklayerdevice{
newLinkLayerDevice(LinkLayerDeviceArgs{
ProviderID: "magic",
MachineID: "bar",
Name: "foo",
MTU: 54,
Type: "loopback",
MACAddress: "DEADBEEF",
IsAutoStart: true,
IsUp: true,
ParentName: "bam",
// V2 adds the VirtualPortType field
VirtualPortType: "ovs",
}),
newLinkLayerDevice(LinkLayerDeviceArgs{Name: "weeee"}),
},
}
bytes, err := yaml.Marshal(initial)
c.Assert(err, jc.ErrorIsNil)
var source map[string]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
devices, err := importLinkLayerDevices(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(devices, jc.DeepEquals, initial.LinkLayerDevices_)
}