Skip to content

Commit 76c6e0f

Browse files
committed
dune build @fmt
1 parent 1ff67d7 commit 76c6e0f

File tree

1 file changed

+119
-93
lines changed

1 file changed

+119
-93
lines changed

test/config_tests.ml

+119-93
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ let opt_eq f a b =
1111
| None, Some _ | Some _, None -> false
1212

1313
let ipv4_eq a b = Ipaddr.V4.compare a b = 0
14-
1514
let ipv6_eq a b = Ipaddr.V6.compare a b = 0
16-
1715
let mac_eq a b = Macaddr.compare a b = 0
1816

1917
let mode_eq a b =
@@ -33,21 +31,23 @@ let dhcp_range_t =
3331
Alcotest.testable pp_dhcp_range equal
3432

3533
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
3939
| `Any_client_id, `Any_client_id -> true
4040
| `Client_id id, `Client_id id' -> String.equal id id'
4141
| `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
5151
in
5252
Alcotest.testable pp_dhcp_config equal
5353

@@ -109,126 +109,152 @@ let ok_dhcp_range_static () =
109109
"DHCP range with static is good" (Ok expected)
110110
(parse_one_arg dhcp_range input))
111111

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 () =
113114
{ id; nets; tags; macs; ipv4; ipv6; lease_time; ignore; domain_name }
114115

115116
let ok_dhcp_host_thedoctor () =
116117
let input = "00:00:5e:00:53:42,thedoctor,192.168.0.10" in
117118
let expected =
118119
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" ]
120121
~domain_name:(Domain_name.of_string_exn "thedoctor")
121122
~ipv4:(Ipaddr.V4.of_string_exn "192.168.0.10")
122123
()
123124
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)
126128

127129
let ok_dhcp_host_tardis () =
128130
let input = "00:00:5e:00:53:01,00:00:5e:00:53:02,tardis,192.168.0.22" in
129131
let expected =
130132
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+
]
133138
~domain_name:(Domain_name.of_string_exn "tardis")
134139
~ipv4:(Ipaddr.V4.of_string_exn "192.168.0.22")
135140
()
136141
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)
139145

140146
let ok_dhcp_host_sonicscrewdriver () =
141147
let input = "00:00:5e:00:53:08,sonicscrewdriver,192.168.0.23" in
142148
let expected =
143149
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" ]
145151
~domain_name:(Domain_name.of_string_exn "sonicscrewdriver")
146152
~ipv4:(Ipaddr.V4.of_string_exn "192.168.0.23")
147153
()
148154
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)
151158

152159
let ok_dhcp_host_apollon () =
153160
let input = "52:54:00:42:6a:43,apollon,10.10.10.51,infinite" in
154161
let expected =
155162
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" ]
157164
~domain_name:(Domain_name.of_string_exn "apollon")
158165
~ipv4:(Ipaddr.V4.of_string_exn "10.10.10.51")
159166
~lease_time:(1 lsl 32) (* infinite *)
160167
()
161168
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)
164172

165173
let ok_dhcp_host_dnsmasq_conf_example =
166174
let to_test (name, input, expected) =
167-
(name, `Quick, fun () ->
175+
( name,
176+
`Quick,
177+
fun () ->
168178
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) )
172181
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+
]
232258

233259
let tests =
234260
[
@@ -239,8 +265,8 @@ let tests =
239265
("DHCP host tardis", `Quick, ok_dhcp_host_tardis);
240266
("DHCP host sonicscrewdriver", `Quick, ok_dhcp_host_sonicscrewdriver);
241267
("DHCP host apollon", `Quick, ok_dhcp_host_apollon);
242-
] @
243-
ok_dhcp_host_dnsmasq_conf_example
268+
]
269+
@ ok_dhcp_host_dnsmasq_conf_example
244270

245271
let string_of_file filename =
246272
let config_dir = "sample-configuration-files" in

0 commit comments

Comments
 (0)