Skip to content

Commit 983a48a

Browse files
authored
gencert testing: use human-readable errors for validation (#6471)
This is done using the API errors, and quite useful when adding tests or changing them to interpret the results
2 parents be8e7b3 + da22219 commit 983a48a

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
@@ -179,11 +179,20 @@ let test_valid_leaf_cert pem_leaf time pkey () =
179179
match validate_pem_chain ~pem_leaf ~pem_chain:None time pkey with
180180
| Ok _ ->
181181
()
182-
| Error (`Msg (_, msg)) ->
182+
| Error (`Msg err) ->
183+
let err_to_str (name, params) =
184+
let Datamodel_types.{err_doc; err_params; _} =
185+
Hashtbl.find Datamodel_errors.errors name
186+
in
187+
let args = List.combine err_params params in
188+
Format.asprintf "%s %a" err_doc
189+
Fmt.(Dump.list (pair ~sep:(Fmt.any ":@ ") string string))
190+
args
191+
in
183192
Alcotest.fail
184193
(Format.asprintf "Valid certificate could not be validated: %a"
185-
Fmt.(Dump.list string)
186-
msg
194+
(Fmt.of_to_string err_to_str)
195+
err
187196
)
188197

189198
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)