Skip to content

Commit

Permalink
xen-api-client: run tests with alcotest
Browse files Browse the repository at this point in the history
Also generate opam metadata with dune

This is the last user of ounit in the repository

Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
  • Loading branch information
psafont committed Jun 13, 2024
1 parent 1253513 commit f74ee18
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 81 deletions.
17 changes: 17 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xen-api-client/lib_test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
(package xen-api-client)
(libraries
dune-build-info
alcotest
rpclib.xml
ounit2
uri
xapi-client
xapi-types
Expand Down
38 changes: 16 additions & 22 deletions ocaml/xen-api-client/lib_test/xen_api_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* GNU Lesser General Public License for more details.
*)

open OUnit
open Xen_api

module Fake_IO = struct
Expand Down Expand Up @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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)
]
)
]
60 changes: 36 additions & 24 deletions xen-api-client.opam
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 0 additions & 34 deletions xen-api-client.opam.template

This file was deleted.

0 comments on commit f74ee18

Please sign in to comment.