Skip to content

Commit da22219

Browse files
committed
gencert testing: use human-readable errors for validation
This is done using the API errors. The use of Hashtbl.find is warranted, if the name is missing from the table something very bad has happened and would have had to raise an error anyway. Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent 418b610 commit da22219

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

ocaml/gencert/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
rresult
6565
x509
6666
xapi-consts
67+
xapi-datamodel
6768
xapi-stdext-unix
6869
)
6970
(deps

ocaml/gencert/test_lib.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,20 @@ let test_valid_leaf_cert pem_leaf time pkey () =
166166
match validate_pem_chain ~pem_leaf ~pem_chain:None time pkey with
167167
| Ok _ ->
168168
()
169-
| Error (`Msg (_, msg)) ->
169+
| Error (`Msg err) ->
170+
let err_to_str (name, params) =
171+
let Datamodel_types.{err_doc; err_params; _} =
172+
Hashtbl.find Datamodel_errors.errors name
173+
in
174+
let args = List.combine err_params params in
175+
Format.asprintf "%s %a" err_doc
176+
Fmt.(Dump.list (pair ~sep:(Fmt.any ":@ ") string string))
177+
args
178+
in
170179
Alcotest.fail
171180
(Format.asprintf "Valid certificate could not be validated: %a"
172-
Fmt.(Dump.list string)
173-
msg
181+
(Fmt.of_to_string err_to_str)
182+
err
174183
)
175184

176185
let test_invalid_cert pem_leaf time pkey error reason =

quality-gate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ unixgetenv () {
110110
}
111111

112112
hashtblfind () {
113-
N=34
113+
N=35
114114
# Looks for all .ml files except the ones using Core.Hashtbl.find,
115115
# which already returns Option
116116
HASHTBLFIND=$(git grep -P -r --count 'Hashtbl.find(?!_opt)' -- '**/*.ml' ':!ocaml/xapi-storage-script/main.ml' | cut -d ':' -f 2 | paste -sd+ - | bc)

0 commit comments

Comments
 (0)