This repository has been archived by the owner on Sep 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestAPI.ml
76 lines (65 loc) · 2.13 KB
/
TestAPI.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
open OUnit
open TestCommon
let tests =
"API" >::
bracket_oasis_db
(* Pre start *)
ignore
(* Main *)
(fun ocs ->
let base_url =
ocs.ocs_base_url^"api"
in
let ctxt =
!odb
in
(* Upload a package *)
let () =
ODBCurl.with_curl
(fun curl ->
let write_fun = String.length in
Curl.set_verbose curl !verbose;
Curl.set_followlocation curl true;
Curl.set_failonerror curl true;
Curl.set_writefunction curl write_fun;
(* Login *)
Curl.set_url curl (base_url^"/login?login=admin1&password=");
Curl.set_cookiefile curl ""; (* Enabled in-memory cookie *)
Curl.perform curl;
(* Upload *)
Curl.set_url curl (base_url^"/upload");
Curl.set_post curl true;
Curl.set_httppost curl
[Curl.CURLFORM_CONTENT("publink", "toto", Curl.DEFAULT);
Curl.CURLFORM_FILE("tarball",
in_data_dir "ocaml-moifile-0.1.0.tar.gz",
Curl.DEFAULT)];
Curl.perform curl;
(* Logout *)
Curl.set_url curl (base_url^"/logout");
Curl.set_post curl false;
Curl.perform curl)
in
let lst =
ODBREST.Pkg.list ~ctxt base_url ()
in
let lst' =
List.map
(fun pkg ->
pkg.ODBPkg.pkg_name,
OASISVersion.string_of_version
(ODBREST.PkgVer.latest ~ctxt base_url pkg.ODBPkg.pkg_name))
lst
in
assert_equal
~msg:"list of latest packages"
~printer:(fun lst ->
("["^(String.concat "; "
(List.map
(fun (p, v) ->
p^", "^v)
lst))^"]"))
["ocaml-moifile", "0.1.0"]
lst')
(* Post stop *)
ignore