|
| 1 | +(* |
| 2 | + * Copyright (C) 2014 Citrix Systems Inc. |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published |
| 6 | + * by the Free Software Foundation; version 2.1 only. with the special |
| 7 | + * exception on linking described in file LICENSE. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. |
| 13 | + *) |
| 14 | + |
| 15 | +open OUnit |
| 16 | +open Test_common |
| 17 | + |
| 18 | +let test_split_host_port () = |
| 19 | + let split = Workload_balancing.split_host_port in |
| 20 | + let assert_succeed url host port = |
| 21 | + assert_equal (split url) (host, port) |
| 22 | + in |
| 23 | + let assert_raise_url_invalid url = |
| 24 | + assert_raises_api_error Api_errors.wlb_url_invalid ~args:[url] (fun () -> split url) |
| 25 | + in |
| 26 | + |
| 27 | + (* succeed cases *) |
| 28 | + assert_succeed "192.168.0.1:80" "192.168.0.1" 80; |
| 29 | + assert_succeed "hostname.com:80" "hostname.com" 80; |
| 30 | + assert_succeed "[fe80::a085:31cf:b31a:6a]:80" "fe80::a085:31cf:b31a:6a" 80; |
| 31 | + |
| 32 | + (* missing port number *) |
| 33 | + assert_raise_url_invalid "192.168.0.1"; |
| 34 | + assert_raise_url_invalid "hostname.noport.com"; |
| 35 | + assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a]"; |
| 36 | + |
| 37 | + (* non-integer port *) |
| 38 | + assert_raise_url_invalid "192.168.0.1:http"; |
| 39 | + assert_raise_url_invalid "hostname.com:port"; |
| 40 | + assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a]:ipv6"; |
| 41 | + |
| 42 | + (* malformed IPv6 host port peers *) |
| 43 | + assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a]80"; |
| 44 | + assert_raise_url_invalid "[fe80::a085:31cf:b31a:6a:80"; |
| 45 | + |
| 46 | + (* others *) |
| 47 | + assert_raise_url_invalid "http://example.com:80/" |
| 48 | + |
| 49 | +let test = |
| 50 | + "test_workload_balancing" >::: |
| 51 | + [ |
| 52 | + "test_split_host_port" >:: test_split_host_port; |
| 53 | + ] |
0 commit comments