Skip to content

Commit bd8c79a

Browse files
committed
CA-422071: add unit test for Host.create_params
Every newly added field must have an entry in Host.create_params, otherwise these settings could be lost on pool join. Signed-off-by: Edwin Török <[email protected]>
1 parent 06c1d62 commit bd8c79a

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

ocaml/idl/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
)
6565

6666
(tests
67-
(names schematest test_datetimes)
67+
(names schematest test_datetimes test_host)
6868
(modes exe)
69-
(modules schematest test_datetimes)
69+
(modules schematest test_datetimes test_host)
7070
(libraries
7171
astring
7272
rpclib.core

ocaml/idl/test_host.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module DT = Datamodel_types
2+
module FieldSet = Astring.String.Set
3+
4+
let recent_field (f : DT.field) = f.lifecycle.transitions = []
5+
6+
let rec field_full_names = function
7+
| DT.Field f ->
8+
if recent_field f then
9+
f.full_name |> String.concat "_" |> Seq.return
10+
else
11+
Seq.empty
12+
| DT.Namespace (_, xs) ->
13+
xs |> List.to_seq |> Seq.concat_map field_full_names
14+
15+
let () =
16+
let create_params =
17+
Datamodel_host.create_params
18+
|> List.map (fun p -> p.DT.param_name)
19+
|> FieldSet.of_list
20+
and fields =
21+
Datamodel_host.t.contents
22+
|> List.to_seq
23+
|> Seq.concat_map field_full_names
24+
|> FieldSet.of_seq
25+
in
26+
let missing_in_create_params = FieldSet.diff fields create_params in
27+
if not (FieldSet.is_empty missing_in_create_params) then (
28+
Format.eprintf "Missing fields in create_params: %a@." FieldSet.dump
29+
missing_in_create_params ;
30+
exit 1
31+
)

ocaml/idl/test_host.mli

Whitespace-only changes.

0 commit comments

Comments
 (0)