forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_workload_balancing.ml
45 lines (40 loc) · 1.78 KB
/
test_workload_balancing.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
(*
* Copyright (C) 2014 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)
let split = Workload_balancing.split_host_port
let assert_succeed url host port =
Alcotest.(check (pair string int))
"test_split_host_port" (host, port) (split url)
let assert_raise_url_invalid url =
Alcotest.check_raises "wlb URL should be invalid"
Api_errors.(Server_error (wlb_url_invalid, [url]))
(fun () -> split url |> ignore)
let test_split_host_port () =
(* succeed cases *)
assert_succeed "192.168.0.1:80" "192.168.0.1" 80 ;
assert_succeed "hostname.com:80" "hostname.com" 80 ;
assert_succeed "[fe80::a085:31cf:b31a:6a]:80" "fe80::a085:31cf:b31a:6a" 80 ;
(* missing port number *)
assert_raise_url_invalid "192.168.0.1" ;
assert_raise_url_invalid "hostname.noport.com" ;
assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a]" ;
(* non-integer port *)
assert_raise_url_invalid "192.168.0.1:http" ;
assert_raise_url_invalid "hostname.com:port" ;
assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a]:ipv6" ;
(* malformed IPv6 host port peers *)
assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a]80" ;
assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a:80" ;
(* others *)
assert_raise_url_invalid "http://example.com:80/"
let test = [("test_split_host_port", `Quick, test_split_host_port)]