@@ -11,9 +11,7 @@ let opt_eq f a b =
11
11
| None , Some _ | Some _ , None -> false
12
12
13
13
let ipv4_eq a b = Ipaddr.V4. compare a b = 0
14
-
15
14
let ipv6_eq a b = Ipaddr.V6. compare a b = 0
16
-
17
15
let mac_eq a b = Macaddr. compare a b = 0
18
16
19
17
let mode_eq a b =
@@ -33,21 +31,23 @@ let dhcp_range_t =
33
31
Alcotest. testable pp_dhcp_range equal
34
32
35
33
let dhcp_host_t =
36
- let equal { id; nets; tags; macs; ipv4; ipv6; lease_time; ignore; domain_name } b =
37
- Option. equal (fun id id' ->
38
- match id, id' with
34
+ let equal
35
+ { id; nets; tags; macs; ipv4; ipv6; lease_time; ignore; domain_name } b =
36
+ Option. equal
37
+ (fun id id' ->
38
+ match (id, id') with
39
39
| `Any_client_id , `Any_client_id -> true
40
40
| `Client_id id , `Client_id id' -> String. equal id id'
41
41
| `Any_client_id , `Client_id _ | `Client_id _ , `Any_client_id -> false )
42
- id b.id &&
43
- List. equal String. equal nets b.nets &&
44
- List. equal String. equal tags b.tags &&
45
- List. equal mac_eq macs b.macs &&
46
- Option. equal ipv4_eq ipv4 b.ipv4 &&
47
- Option. equal ipv6_eq ipv6 b.ipv6 &&
48
- Option. equal Int. equal lease_time b.lease_time &&
49
- Bool. equal ignore b.ignore &&
50
- Option. equal Domain_name. equal domain_name b.domain_name
42
+ id b.id
43
+ && List. equal String. equal nets b.nets
44
+ && List. equal String. equal tags b.tags
45
+ && List. equal mac_eq macs b.macs
46
+ && Option. equal ipv4_eq ipv4 b.ipv4
47
+ && Option. equal ipv6_eq ipv6 b.ipv6
48
+ && Option. equal Int. equal lease_time b.lease_time
49
+ && Bool. equal ignore b.ignore
50
+ && Option. equal Domain_name. equal domain_name b.domain_name
51
51
in
52
52
Alcotest. testable pp_dhcp_config equal
53
53
@@ -109,126 +109,152 @@ let ok_dhcp_range_static () =
109
109
" DHCP range with static is good" (Ok expected)
110
110
(parse_one_arg dhcp_range input))
111
111
112
- let make_dhcp_config ?id ?(nets =[] ) ?(tags =[] ) ?(macs =[] ) ?ipv4 ?ipv6 ?lease_time ?(ignore =false ) ?domain_name () =
112
+ let make_dhcp_config ?id ?(nets = [] ) ?(tags = [] ) ?(macs = [] ) ?ipv4 ?ipv6
113
+ ?lease_time ?(ignore = false ) ?domain_name () =
113
114
{ id; nets; tags; macs; ipv4; ipv6; lease_time; ignore; domain_name }
114
115
115
116
let ok_dhcp_host_thedoctor () =
116
117
let input = " 00:00:5e:00:53:42,thedoctor,192.168.0.10" in
117
118
let expected =
118
119
make_dhcp_config
119
- ~macs: [Macaddr. of_string_exn " 00:00:5e:00:53:42" ]
120
+ ~macs: [ Macaddr. of_string_exn " 00:00:5e:00:53:42" ]
120
121
~domain_name: (Domain_name. of_string_exn " thedoctor" )
121
122
~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.10" )
122
123
()
123
124
in
124
- Alcotest. (check (result dhcp_host_t msg_t)) " DHCP host thedoctor is good"
125
- (Ok expected) (parse_one_arg dhcp_host input)
125
+ Alcotest. (check (result dhcp_host_t msg_t))
126
+ " DHCP host thedoctor is good" (Ok expected)
127
+ (parse_one_arg dhcp_host input)
126
128
127
129
let ok_dhcp_host_tardis () =
128
130
let input = " 00:00:5e:00:53:01,00:00:5e:00:53:02,tardis,192.168.0.22" in
129
131
let expected =
130
132
make_dhcp_config
131
- ~macs: Macaddr. [of_string_exn " 00:00:5e:00:53:01" ;
132
- of_string_exn " 00:00:5e:00:53:02" ]
133
+ ~macs:
134
+ Macaddr.
135
+ [
136
+ of_string_exn " 00:00:5e:00:53:01" ; of_string_exn " 00:00:5e:00:53:02" ;
137
+ ]
133
138
~domain_name: (Domain_name. of_string_exn " tardis" )
134
139
~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.22" )
135
140
()
136
141
in
137
- Alcotest. (check (result dhcp_host_t msg_t)) " DHCP host tardis is good"
138
- (Ok expected) (parse_one_arg dhcp_host input)
142
+ Alcotest. (check (result dhcp_host_t msg_t))
143
+ " DHCP host tardis is good" (Ok expected)
144
+ (parse_one_arg dhcp_host input)
139
145
140
146
let ok_dhcp_host_sonicscrewdriver () =
141
147
let input = " 00:00:5e:00:53:08,sonicscrewdriver,192.168.0.23" in
142
148
let expected =
143
149
make_dhcp_config
144
- ~macs: [Macaddr. of_string_exn " 00:00:5e:00:53:08" ]
150
+ ~macs: [ Macaddr. of_string_exn " 00:00:5e:00:53:08" ]
145
151
~domain_name: (Domain_name. of_string_exn " sonicscrewdriver" )
146
152
~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.23" )
147
153
()
148
154
in
149
- Alcotest. (check (result dhcp_host_t msg_t)) " DHCP host sonicscrewdriver is good"
150
- (Ok expected) (parse_one_arg dhcp_host input)
155
+ Alcotest. (check (result dhcp_host_t msg_t))
156
+ " DHCP host sonicscrewdriver is good" (Ok expected)
157
+ (parse_one_arg dhcp_host input)
151
158
152
159
let ok_dhcp_host_apollon () =
153
160
let input = " 52:54:00:42:6a:43,apollon,10.10.10.51,infinite" in
154
161
let expected =
155
162
make_dhcp_config
156
- ~macs: [Macaddr. of_string_exn " 52:54:00:42:6a:43" ]
163
+ ~macs: [ Macaddr. of_string_exn " 52:54:00:42:6a:43" ]
157
164
~domain_name: (Domain_name. of_string_exn " apollon" )
158
165
~ipv4: (Ipaddr.V4. of_string_exn " 10.10.10.51" )
159
166
~lease_time: (1 lsl 32 ) (* infinite *)
160
167
()
161
168
in
162
- Alcotest. (check (result dhcp_host_t msg_t)) " DHCP host apollon is good"
163
- (Ok expected) (parse_one_arg dhcp_host input)
169
+ Alcotest. (check (result dhcp_host_t msg_t))
170
+ " DHCP host apollon is good" (Ok expected)
171
+ (parse_one_arg dhcp_host input)
164
172
165
173
let ok_dhcp_host_dnsmasq_conf_example =
166
174
let to_test (name , input , expected ) =
167
- (name, `Quick , fun () ->
175
+ ( name,
176
+ `Quick ,
177
+ fun () ->
168
178
Alcotest. (check (result dhcp_host_t msg_t))
169
- (name ^ " is good" )
170
- (Ok expected)
171
- (parse_one_arg dhcp_host input))
179
+ (name ^ " is good" ) (Ok expected)
180
+ (parse_one_arg dhcp_host input) )
172
181
in
173
- List. map to_test [
174
- (" First dhcp-host from dnsmasq.conf.example" ,
175
- " 11:22:33:44:55:66,192.168.0.60" ,
176
- make_dhcp_config ~macs: [Macaddr. of_string_exn " 11:22:33:44:55:66" ]
177
- ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" ) () );
178
- (" Second dhcp-host from dnsmasq.conf.example" ,
179
- " 11:22:33:44:55:66,fred" ,
180
- make_dhcp_config ~macs: [Macaddr. of_string_exn " 11:22:33:44:55:66" ]
181
- ~domain_name: (Domain_name. of_string_exn " fred" ) () );
182
- (" Third dhcp-host from dnsmasq.conf.example" ,
183
- " 11:22:33:44:55:66,fred,192.168.0.60,45m" ,
184
- make_dhcp_config ~macs: [Macaddr. of_string_exn " 11:22:33:44:55:66" ]
185
- ~domain_name: (Domain_name. of_string_exn " fred" )
186
- ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" )
187
- ~lease_time: (45 * 60 ) () );
188
- (" Fourth dhcp-host from dnsmasq.conf.example" ,
189
- " 11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.60" ,
190
- make_dhcp_config ~macs: Macaddr. [of_string_exn " 11:22:33:44:55:66" ;
191
- of_string_exn " 12:34:56:78:90:12" ]
192
- ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" ) () );
193
- (" Fifth dhcp-host from dnsmasq.conf.example" ,
194
- " bert,192.168.0.70,infinite" ,
195
- make_dhcp_config ~domain_name: (Domain_name. of_string_exn " bert" )
196
- ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.70" )
197
- ~lease_time: (1 lsl 32 ) () );
198
- (" Sixth dhcp-host from dnsmasq.conf.example" ,
199
- " id:01:02:02:04,192.168.0.60" ,
200
- make_dhcp_config ~id: (`Client_id " \x01\x02\x02\x04 " )
201
- ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" ) () );
202
- (* skipping seventh as it's similar to above, but is infiniband in a manner we wouldn't care about *)
203
- (" Eigth dhcp-host from dnsmasq.conf.example" ,
204
- " id:marjorie,192.168.0.60" ,
205
- make_dhcp_config ~id: (`Client_id " marjorie" )
206
- ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" ) () );
207
- (" Ninth dhcp-host from dnsmasq.conf.example" ,
208
- " judge" ,
209
- make_dhcp_config ~domain_name: (Domain_name. of_string_exn " judge" )
210
- () );
211
- (" Tenth dhcp-host from dnsmasq.conf.example" ,
212
- " 11:22:33:44:55:66,ignore" ,
213
- make_dhcp_config ~macs: [Macaddr. of_string_exn " 11:22:33:44:55:66" ]
214
- ~ignore: true () );
215
- (" Eleventh dhcp-host from dnsmasq.conf.example" ,
216
- " 11:22:33:44:55:66,id:*" ,
217
- make_dhcp_config ~id: `Any_client_id
218
- ~macs: [Macaddr. of_string_exn " 11:22:33:44:55:66" ] () );
219
- (" Twelvth dhcp-host from dnsmasq.conf.example" ,
220
- " 11:22:33:44:55:66,set:red" ,
221
- make_dhcp_config ~macs: [Macaddr. of_string_exn " 11:22:33:44:55:66" ]
222
- ~nets: [" red" ] () );
223
- (* TODO:
224
- ("Thirteenth dhcp-host from dnsmasq.conf.example",
225
- "11:22:33:*:*:*,set:red",
226
- _);
227
- ("Fourteenth dhcp-host from dnsmasq.conf.example",
228
- "id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5]",
229
- _);
230
- *)
231
- ]
182
+ List. map to_test
183
+ [
184
+ ( " First dhcp-host from dnsmasq.conf.example" ,
185
+ " 11:22:33:44:55:66,192.168.0.60" ,
186
+ make_dhcp_config
187
+ ~macs: [ Macaddr. of_string_exn " 11:22:33:44:55:66" ]
188
+ ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" )
189
+ () );
190
+ ( " Second dhcp-host from dnsmasq.conf.example" ,
191
+ " 11:22:33:44:55:66,fred" ,
192
+ make_dhcp_config
193
+ ~macs: [ Macaddr. of_string_exn " 11:22:33:44:55:66" ]
194
+ ~domain_name: (Domain_name. of_string_exn " fred" )
195
+ () );
196
+ ( " Third dhcp-host from dnsmasq.conf.example" ,
197
+ " 11:22:33:44:55:66,fred,192.168.0.60,45m" ,
198
+ make_dhcp_config
199
+ ~macs: [ Macaddr. of_string_exn " 11:22:33:44:55:66" ]
200
+ ~domain_name: (Domain_name. of_string_exn " fred" )
201
+ ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" )
202
+ ~lease_time: (45 * 60 ) () );
203
+ ( " Fourth dhcp-host from dnsmasq.conf.example" ,
204
+ " 11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.60" ,
205
+ make_dhcp_config
206
+ ~macs:
207
+ Macaddr.
208
+ [
209
+ of_string_exn " 11:22:33:44:55:66" ;
210
+ of_string_exn " 12:34:56:78:90:12" ;
211
+ ]
212
+ ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" )
213
+ () );
214
+ ( " Fifth dhcp-host from dnsmasq.conf.example" ,
215
+ " bert,192.168.0.70,infinite" ,
216
+ make_dhcp_config
217
+ ~domain_name: (Domain_name. of_string_exn " bert" )
218
+ ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.70" )
219
+ ~lease_time: (1 lsl 32 ) () );
220
+ ( " Sixth dhcp-host from dnsmasq.conf.example" ,
221
+ " id:01:02:02:04,192.168.0.60" ,
222
+ make_dhcp_config ~id: (`Client_id " \x01\x02\x02\x04 " )
223
+ ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" )
224
+ () );
225
+ (* skipping seventh as it's similar to above, but is infiniband in a manner we wouldn't care about *)
226
+ ( " Eigth dhcp-host from dnsmasq.conf.example" ,
227
+ " id:marjorie,192.168.0.60" ,
228
+ make_dhcp_config ~id: (`Client_id " marjorie" )
229
+ ~ipv4: (Ipaddr.V4. of_string_exn " 192.168.0.60" )
230
+ () );
231
+ ( " Ninth dhcp-host from dnsmasq.conf.example" ,
232
+ " judge" ,
233
+ make_dhcp_config ~domain_name: (Domain_name. of_string_exn " judge" ) () );
234
+ ( " Tenth dhcp-host from dnsmasq.conf.example" ,
235
+ " 11:22:33:44:55:66,ignore" ,
236
+ make_dhcp_config
237
+ ~macs: [ Macaddr. of_string_exn " 11:22:33:44:55:66" ]
238
+ ~ignore: true () );
239
+ ( " Eleventh dhcp-host from dnsmasq.conf.example" ,
240
+ " 11:22:33:44:55:66,id:*" ,
241
+ make_dhcp_config ~id: `Any_client_id
242
+ ~macs: [ Macaddr. of_string_exn " 11:22:33:44:55:66" ]
243
+ () );
244
+ ( " Twelvth dhcp-host from dnsmasq.conf.example" ,
245
+ " 11:22:33:44:55:66,set:red" ,
246
+ make_dhcp_config
247
+ ~macs: [ Macaddr. of_string_exn " 11:22:33:44:55:66" ]
248
+ ~nets: [ " red" ] () );
249
+ (* TODO:
250
+ ("Thirteenth dhcp-host from dnsmasq.conf.example",
251
+ "11:22:33:*:*:*,set:red",
252
+ _);
253
+ ("Fourteenth dhcp-host from dnsmasq.conf.example",
254
+ "id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5]",
255
+ _);
256
+ *)
257
+ ]
232
258
233
259
let tests =
234
260
[
@@ -239,8 +265,8 @@ let tests =
239
265
(" DHCP host tardis" , `Quick , ok_dhcp_host_tardis);
240
266
(" DHCP host sonicscrewdriver" , `Quick , ok_dhcp_host_sonicscrewdriver);
241
267
(" DHCP host apollon" , `Quick , ok_dhcp_host_apollon);
242
- ] @
243
- ok_dhcp_host_dnsmasq_conf_example
268
+ ]
269
+ @ ok_dhcp_host_dnsmasq_conf_example
244
270
245
271
let string_of_file filename =
246
272
let config_dir = " sample-configuration-files" in
0 commit comments