forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdhcpcd_test.go
More file actions
141 lines (137 loc) · 3.69 KB
/
dhcpcd_test.go
File metadata and controls
141 lines (137 loc) · 3.69 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package genericitems_test
import (
"net"
"testing"
configitems "github.com/lf-edge/eve/pkg/pillar/dpcreconciler/genericitems"
"github.com/lf-edge/eve/pkg/pillar/types"
)
func TestDhcpcdEqual(t *testing.T) {
type test struct {
name string
item1 configitems.Dhcpcd
item2 configitems.Dhcpcd
expEqual bool
}
var tests = []test{
{
name: "DHCP client for IPv4 only",
item1: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
AddrSubnet: "192.168.1.44/24", // irrelevant
Gateway: net.ParseIP("192.168.1.1"), // irrelevant
DomainName: "mydomain", // irrelevant
NtpServer: net.ParseIP("192.168.1.1"), // irrelevant
Type: types.NtIpv4Only, // must match
},
},
item2: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
Type: types.NtIpv4Only, // must match
},
},
expEqual: true,
},
{
name: "DHCP client with effectively equivalent IP types",
item1: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
Type: types.NT_NOOP, // sometimes we get this in override.json
},
},
item2: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
Type: types.NT_IPV4, // effectively equivalent to NT_NOOP
},
},
expEqual: true,
},
{
name: "DHCP client with effectively different IP types",
item1: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
Type: types.NT_IPV4,
},
},
item2: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
Type: types.NtIpv4Only, // differs in --ipv4only arg
},
},
expEqual: false,
},
{
name: "DHCP client with disabled default route",
item1: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
Gateway: net.ParseIP("0.0.0.0"), // default route is disabled
},
},
item2: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_CLIENT,
// default route is enabled
},
},
expEqual: false,
},
{
name: "equivalent static IP config",
item1: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_STATIC,
AddrSubnet: "192.168.1.44/24",
DomainName: "mydomain",
NtpServer: net.ParseIP("192.168.1.1"),
DnsServers: []net.IP{net.ParseIP("8.8.8.8")},
Type: types.NtIpv4Only, // irrelevant
},
},
item2: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_STATIC,
AddrSubnet: "192.168.1.44/24",
DomainName: "mydomain",
NtpServer: net.ParseIP("192.168.1.1"),
DnsServers: []net.IP{net.ParseIP("8.8.8.8")},
Type: types.NT_IPV4, // irrelevant
},
},
expEqual: true,
},
{
name: "different statically configured DNS servers",
item1: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_STATIC,
AddrSubnet: "192.168.1.44/24",
DomainName: "mydomain",
NtpServer: net.ParseIP("192.168.1.1"),
DnsServers: []net.IP{net.ParseIP("8.8.8.8")}, // does not match
},
},
item2: configitems.Dhcpcd{
DhcpConfig: types.DhcpConfig{
Dhcp: types.DT_STATIC,
AddrSubnet: "192.168.1.44/24",
DomainName: "mydomain",
NtpServer: net.ParseIP("192.168.1.1"),
DnsServers: []net.IP{net.ParseIP("1.1.1.1")}, // does not match
},
},
expEqual: false,
},
}
for _, test := range tests {
if test.item1.Equal(test.item2) != test.expEqual {
t.Errorf("TEST CASE \"%s\" FAILED - Equal() returned: %t, expected: %t",
test.name, test.item1.Equal(test.item2), test.expEqual)
}
}
}