From d04ba273582d6572820661c04e0ea25145f32112 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Wed, 14 Aug 2024 14:10:03 +0800 Subject: [PATCH] CA-397268: Add unit test for valid_device Signed-off-by: Ming Lu --- ocaml/tests/test_xapi_vbd_helpers.ml | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ocaml/tests/test_xapi_vbd_helpers.ml b/ocaml/tests/test_xapi_vbd_helpers.ml index 0aa4ef0a6d1..101abf6dd82 100644 --- a/ocaml/tests/test_xapi_vbd_helpers.ml +++ b/ocaml/tests/test_xapi_vbd_helpers.ml @@ -85,6 +85,34 @@ let test_ca253933_valid_operations () = in List.iter operation_is_valid valid_operations +let test_valid_device () = + let valid_devices = + [ + ("autodetect", `Floppy) + ; ("sda", `Disk) + ; ("sda0", `Disk) + ; ("sdp", `Disk) + ; ("sdp99", `Disk) + ; ("xvda", `Disk) + ; ("xvda0", `Disk) + ; ("xvdp", `Disk) + ; ("xvdp99", `Disk) + ; ("hda", `Disk) + ; ("hda0", `Disk) + ; ("hdp", `Disk) + ; ("hdp99", `Disk) + ; ("fda", `Disk) + ; ("fdb", `Disk) + ; ("0", `CD) + ; ("1", `CD) + ] + in + let check (dev, _type) = + let f = Xapi_vbd_helpers.valid_device in + Alcotest.(check bool) "must be equal" true (f dev ~_type) + in + List.iter check valid_devices + let test = [ ( "test_ca253933_invalid_operations" @@ -92,4 +120,5 @@ let test = , test_ca253933_invalid_operations ) ; ("test_ca253933_valid_operations", `Quick, test_ca253933_valid_operations) + ; ("test_valid_device", `Quick, test_valid_device) ]