From f74ee18fb6e37efae1d490518c844f1a194bc83b Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Thu, 13 Jun 2024 14:49:50 +0100 Subject: [PATCH] xen-api-client: run tests with alcotest Also generate opam metadata with dune This is the last user of ounit in the repository Signed-off-by: Pau Ruiz Safont --- dune-project | 17 ++++++ ocaml/xen-api-client/lib_test/dune | 2 +- ocaml/xen-api-client/lib_test/xen_api_test.ml | 38 +++++------- xen-api-client.opam | 60 +++++++++++-------- xen-api-client.opam.template | 34 ----------- 5 files changed, 70 insertions(+), 81 deletions(-) delete mode 100644 xen-api-client.opam.template diff --git a/dune-project b/dune-project index 461a2b928fa..76088001c4d 100644 --- a/dune-project +++ b/dune-project @@ -34,6 +34,23 @@ (package (name xen-api-client) + (synopsis "Xen-API client library for remotely-controlling a xapi host") + (authors "David Scott" "Anil Madhavapeddy" "Jerome Maloberti" "John Else" "Jon Ludlam" "Thomas Sanders" "Mike McClurg") + (depends + dune-build-info + (alcotest :with-test) + astring + (cohttp (>= "0.22.0")) + re + rpclib + uri + (uuid (= :version)) + (xapi-client (= :version)) + (xapi-idl (= :version)) + (xapi-rrd (= :version)) + (xapi-types (= :version)) + xmlm + ) ) (package diff --git a/ocaml/xen-api-client/lib_test/dune b/ocaml/xen-api-client/lib_test/dune index 70b409f4fb5..12e1921130c 100644 --- a/ocaml/xen-api-client/lib_test/dune +++ b/ocaml/xen-api-client/lib_test/dune @@ -3,8 +3,8 @@ (package xen-api-client) (libraries dune-build-info + alcotest rpclib.xml - ounit2 uri xapi-client xapi-types diff --git a/ocaml/xen-api-client/lib_test/xen_api_test.ml b/ocaml/xen-api-client/lib_test/xen_api_test.ml index 0e7a8a9d753..b8729de197c 100644 --- a/ocaml/xen-api-client/lib_test/xen_api_test.ml +++ b/ocaml/xen-api-client/lib_test/xen_api_test.ml @@ -12,7 +12,6 @@ * GNU Lesser General Public License for more details. *) -open OUnit open Xen_api module Fake_IO = struct @@ -77,7 +76,7 @@ end module C = Client.Client -let test_login_fail _ = +let test_login_fail () = let module M = Xen_api.Make (Fake_IO) in let open Fake_IO in let rpc req = @@ -98,11 +97,11 @@ let test_login_fail _ = () with Xen_api.No_response -> () ) ; - assert_equal ~printer:string_of_float ~msg:"timeofday" 31. !timeofday ; - assert_equal ~printer:string_of_int ~msg:"num_sleeps" 31 !num_sleeps ; + Alcotest.(check @@ float Float.epsilon) "timeofday" 31. !timeofday ; + Alcotest.(check int) "num_sleeps" 31 !num_sleeps ; () -let test_login_success _ = +let test_login_success () = let session_id = "OpaqueRef:9e9cf047-76d7-9f3a-62ca-cb7bacf5a4e1" in let result = Printf.sprintf @@ -138,20 +137,15 @@ let test_login_success _ = C.Session.login_with_password ~rpc ~uname:"root" ~pwd:"password" ~version:"1.0" ~originator:"xen-api test" in - assert_equal ~msg:"session_id" session_id (API.Ref.string_of session_id') - -let _ = - let verbose = ref false in - Arg.parse - [("-verbose", Arg.Unit (fun _ -> verbose := true), "Run in verbose mode")] - (fun x -> Printf.fprintf stderr "Ignoring argument: %s" x) - "Test xen-api protocol code" ; - - let suite = - "xen-api" - >::: [ - "login_fail" >:: test_login_fail - ; "login_success" >:: test_login_success - ] - in - run_test_tt ~verbose:!verbose suite + Alcotest.(check string) "session_id" session_id (API.Ref.string_of session_id') + +let () = + Alcotest.run "xen-api-client" + [ + ( "login" + , [ + ("fail", `Quick, test_login_fail) + ; ("success", `Quick, test_login_success) + ] + ) + ] diff --git a/xen-api-client.opam b/xen-api-client.opam index 0aa625df24e..3c31159d66c 100644 --- a/xen-api-client.opam +++ b/xen-api-client.opam @@ -1,36 +1,48 @@ # This file is generated by dune, edit dune-project instead - opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: [ "David Scott" "Anil Madhavapeddy" "Jerome Maloberti" "John Else" "Jon Ludlam" "Thomas Sanders" "Mike McClurg" ] +synopsis: "Xen-API client library for remotely-controlling a xapi host" +maintainer: ["Xapi project maintainers"] +authors: [ + "David Scott" + "Anil Madhavapeddy" + "Jerome Maloberti" + "John Else" + "Jon Ludlam" + "Thomas Sanders" + "Mike McClurg" +] license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" +homepage: "https://xapi-project.github.io/" bug-reports: "https://github.com/xapi-project/xen-api/issues" -tags: [ - "org:xapi-project" -] -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] depends: [ - "ocaml" - "dune" {>= "2.0"} + "dune" {>= "3.0"} + "dune-build-info" + "alcotest" {with-test} "astring" "cohttp" {>= "0.22.0"} "re" "rpclib" - "xapi-rrd" "uri" - "uuid" - "xapi-client" - "xapi-types" + "uuid" {= version} + "xapi-client" {= version} + "xapi-idl" {= version} + "xapi-rrd" {= version} + "xapi-types" {= version} "xmlm" - "ounit2" {with-test} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] ] -synopsis: - "Xen-API client library for remotely-controlling a xapi host" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} +dev-repo: "git+https://github.com/xapi-project/xen-api.git" diff --git a/xen-api-client.opam.template b/xen-api-client.opam.template deleted file mode 100644 index 3b2b8b6f272..00000000000 --- a/xen-api-client.opam.template +++ /dev/null @@ -1,34 +0,0 @@ -opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: [ "David Scott" "Anil Madhavapeddy" "Jerome Maloberti" "John Else" "Jon Ludlam" "Thomas Sanders" "Mike McClurg" ] -license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -bug-reports: "https://github.com/xapi-project/xen-api/issues" -tags: [ - "org:xapi-project" -] -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -depends: [ - "ocaml" - "dune" {>= "2.0"} - "astring" - "cohttp" {>= "0.22.0"} - "re" - "rpclib" - "xapi-rrd" - "uri" - "uuid" - "xapi-client" - "xapi-types" - "xmlm" - "ounit2" {with-test} -] -synopsis: - "Xen-API client library for remotely-controlling a xapi host" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -}