forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_client.ml
59 lines (54 loc) · 2.03 KB
/
test_client.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(** This module tests more layers of xapi than other tests by using the Client
module to make XenAPI calls. It tests many of the auto-generated files as
these XenAPI calls go through the client, server.ml, message forwarding,
and database layers. *)
let setup_test () =
let __context = Test_common.make_test_database () in
Test_common.make_client_params ~__context
(* Here we should have a unit test for each different type of method, such as
X.create, X.destroy, getters, and setters, to ensure that these are
generated correctly.
We use the Task class for these tests because it is simple enough that we do
not have to mock the storage or any other layers. *)
let test_create () =
let rpc, session_id = setup_test () in
let self =
Client.Client.Task.create ~rpc ~session_id ~label:"task_label"
~description:"task_description"
in
Alcotest.(check string)
"task label" "task_label"
(Client.Client.Task.get_name_label ~rpc ~session_id ~self)
let test_get_alls () =
let rpc, session_id = setup_test () in
let _t1 =
Client.Client.Task.create ~rpc ~session_id ~label:"t1" ~description:""
in
let _t2 =
Client.Client.Task.create ~rpc ~session_id ~label:"t2" ~description:""
in
let _t3 =
Client.Client.Task.create ~rpc ~session_id ~label:"t3" ~description:""
in
let _t4 =
Client.Client.Task.create ~rpc ~session_id ~label:"t4" ~description:""
in
let labels =
Client.Client.Task.get_all ~rpc ~session_id
|> List.map (fun self ->
Client.Client.Task.get_name_label ~rpc ~session_id ~self
)
in
Alcotest.(check (slist string String.compare))
"task labels from get_all" ["t1"; "t2"; "t3"; "t4"] labels ;
let labels =
Client.Client.Task.get_all_records ~rpc ~session_id
|> List.map (fun (_, r) -> r.API.task_name_label)
in
Alcotest.(check (slist string String.compare))
"task labels from get_all_records" ["t1"; "t2"; "t3"; "t4"] labels
let test =
[
("test_create", `Quick, test_create)
; ("test_get_alls", `Quick, test_get_alls)
]