|
14 | 14 |
|
15 | 15 | module T = Test_common
|
16 | 16 |
|
17 |
| -let test_set_remote_and_bundle_repos () = |
| 17 | +let on_repositories f = |
18 | 18 | let __context = T.make_test_database () in
|
19 |
| - let name_label = "remote" in |
20 |
| - let name_description = "remote" in |
21 |
| - let binary_url = "https://repo.example.com" in |
| 19 | + let pool = Helpers.get_pool ~__context in |
| 20 | + let binary_url_1 = "https://repo.example.com" in |
| 21 | + let binary_url_2 = "https://1.1.1.1/repository/enabled" in |
22 | 22 | let source_url = "https://repo-src.example.com" in
|
23 |
| - let gpgkey_path = "" in |
24 | 23 | let ref_remote =
|
25 |
| - Repository.introduce ~__context ~name_label ~name_description ~binary_url |
26 |
| - ~source_url ~update:true ~gpgkey_path |
| 24 | + Repository.introduce ~__context ~name_label:"remote" |
| 25 | + ~name_description:"remote" ~binary_url:binary_url_1 ~source_url |
| 26 | + ~update:true ~gpgkey_path:"" |
27 | 27 | in
|
28 | 28 | let ref_bundle =
|
29 | 29 | Repository.introduce_bundle ~__context ~name_label:"bundle"
|
30 | 30 | ~name_description:"bundle"
|
31 | 31 | in
|
32 |
| - let self = Helpers.get_pool ~__context in |
33 |
| - Alcotest.check_raises "test_set_remote_and_bundle_repos" |
34 |
| - Api_errors.(Server_error (bundle_repo_should_be_single_enabled, [])) |
35 |
| - (fun () -> |
36 |
| - Xapi_pool.set_repositories ~__context ~self |
37 |
| - ~value:[ref_remote; ref_bundle] |
38 |
| - ) |
39 |
| - |
40 |
| -let test_add_bundle_repo () = |
41 |
| - let __context = T.make_test_database () in |
42 |
| - let name_label = "remote" in |
43 |
| - let name_description = "remote" in |
44 |
| - let binary_url = "https://repo.example.com" in |
45 |
| - let source_url = "https://repo-src.example.com" in |
46 |
| - let gpgkey_path = "" in |
47 |
| - let ref_remote = |
48 |
| - Repository.introduce ~__context ~name_label ~name_description ~binary_url |
49 |
| - ~source_url ~update:true ~gpgkey_path |
| 32 | + let ref_remote_pool = |
| 33 | + Repository.introduce_remote_pool ~__context ~name_label:"remote_pool" |
| 34 | + ~binary_url:binary_url_2 ~name_description:"remote_pool" ~certificate:"" |
50 | 35 | in
|
51 |
| - let ref_bundle = |
52 |
| - Repository.introduce_bundle ~__context ~name_label:"bundle" |
53 |
| - ~name_description:"bundle" |
54 |
| - in |
55 |
| - let self = Helpers.get_pool ~__context in |
56 |
| - Alcotest.check_raises "test_add_bundle_repo" |
57 |
| - Api_errors.(Server_error (bundle_repo_should_be_single_enabled, [])) |
58 |
| - (fun () -> |
59 |
| - Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote] ; |
60 |
| - Xapi_pool.add_repository ~__context ~self ~value:ref_bundle |
61 |
| - ) |
| 36 | + f __context pool ref_remote ref_bundle ref_remote_pool |
62 | 37 |
|
63 |
| -let test_add_remote_repo () = |
64 |
| - let __context = T.make_test_database () in |
65 |
| - let name_label = "remote" in |
66 |
| - let name_description = "remote" in |
67 |
| - let binary_url = "https://repo.example.com" in |
68 |
| - let source_url = "https://repo-src.example.com" in |
69 |
| - let gpgkey_path = "" in |
70 |
| - let ref_remote = |
71 |
| - Repository.introduce ~__context ~name_label ~name_description ~binary_url |
72 |
| - ~source_url ~update:true ~gpgkey_path |
73 |
| - in |
74 |
| - let ref_bundle = |
75 |
| - Repository.introduce_bundle ~__context ~name_label:"bundle" |
76 |
| - ~name_description:"bundle" |
77 |
| - in |
78 |
| - let self = Helpers.get_pool ~__context in |
79 |
| - Alcotest.check_raises "test_add_remote_repo" |
80 |
| - Api_errors.(Server_error (bundle_repo_should_be_single_enabled, [])) |
81 |
| - (fun () -> |
| 38 | +let test_set_repositories () = |
| 39 | + on_repositories (fun __context self ref_remote ref_bundle ref_remote_pool -> |
| 40 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote] ; |
82 | 41 | Xapi_pool.set_repositories ~__context ~self ~value:[ref_bundle] ;
|
83 |
| - Xapi_pool.add_repository ~__context ~self ~value:ref_remote |
84 |
| - ) |
| 42 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote_pool] ; |
| 43 | + Alcotest.check_raises "test_set_repositories_1" |
| 44 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 45 | + (fun () -> |
| 46 | + Xapi_pool.set_repositories ~__context ~self |
| 47 | + ~value:[ref_remote; ref_bundle] |
| 48 | + ) ; |
| 49 | + Alcotest.check_raises "test_set_repositories_2" |
| 50 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 51 | + (fun () -> |
| 52 | + Xapi_pool.set_repositories ~__context ~self |
| 53 | + ~value:[ref_remote_pool; ref_bundle] |
| 54 | + ) ; |
| 55 | + Alcotest.check_raises "test_set_repositories_3" |
| 56 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 57 | + (fun () -> |
| 58 | + Xapi_pool.set_repositories ~__context ~self |
| 59 | + ~value:[ref_remote; ref_remote_pool] |
| 60 | + ) |
| 61 | + ) |
85 | 62 |
|
86 |
| -let test_can_not_enable_bundle_repo_auto_sync () = |
87 |
| - let __context = T.make_test_database () in |
88 |
| - let ref_bundle = |
89 |
| - Repository.introduce_bundle ~__context ~name_label:"bundle" |
90 |
| - ~name_description:"bundle" |
91 |
| - in |
92 |
| - let self = Helpers.get_pool ~__context in |
93 |
| - Alcotest.check_raises "test_can_not_enable_bundle_repo_auto_sync" |
94 |
| - Api_errors.(Server_error (can_not_sync_updates, [])) |
95 |
| - (fun () -> |
96 |
| - Xapi_pool.set_repositories ~__context ~self ~value:[ref_bundle] ; |
97 |
| - Xapi_pool.set_update_sync_enabled ~__context ~self ~value:true |
98 |
| - ) |
| 63 | +let test_add_repository () = |
| 64 | + on_repositories (fun __context self ref_remote ref_bundle ref_remote_pool -> |
| 65 | + Alcotest.check_raises "test_add_repository_1" |
| 66 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 67 | + (fun () -> |
| 68 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote] ; |
| 69 | + Xapi_pool.add_repository ~__context ~self ~value:ref_bundle |
| 70 | + ) ; |
| 71 | + Alcotest.check_raises "test_add_repository_2" |
| 72 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 73 | + (fun () -> |
| 74 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote] ; |
| 75 | + Xapi_pool.add_repository ~__context ~self ~value:ref_remote_pool |
| 76 | + ) ; |
| 77 | + Alcotest.check_raises "test_add_repository_3" |
| 78 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 79 | + (fun () -> |
| 80 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote_pool] ; |
| 81 | + Xapi_pool.add_repository ~__context ~self ~value:ref_bundle |
| 82 | + ) ; |
| 83 | + Alcotest.check_raises "test_add_repository_4" |
| 84 | + Api_errors.(Server_error (repo_should_be_single_one_enabled, [])) |
| 85 | + (fun () -> |
| 86 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_bundle] ; |
| 87 | + Xapi_pool.add_repository ~__context ~self ~value:ref_remote_pool |
| 88 | + ) |
| 89 | + ) |
| 90 | + |
| 91 | +let test_enable_periodic_repo_sync () = |
| 92 | + on_repositories (fun __context self ref_remote ref_bundle ref_remote_pool -> |
| 93 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote] ; |
| 94 | + Xapi_pool.set_update_sync_enabled ~__context ~self ~value:true ; |
| 95 | + Alcotest.check_raises "test_enable_periodic_repo_sync_1" |
| 96 | + Api_errors.(Server_error (can_not_periodic_sync_updates, [])) |
| 97 | + (fun () -> |
| 98 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_bundle] ; |
| 99 | + Xapi_pool.set_update_sync_enabled ~__context ~self ~value:true |
| 100 | + ) ; |
| 101 | + Alcotest.check_raises "test_enable_periodic_repo_sync_2" |
| 102 | + Api_errors.(Server_error (can_not_periodic_sync_updates, [])) |
| 103 | + (fun () -> |
| 104 | + Xapi_pool.set_repositories ~__context ~self ~value:[ref_remote_pool] ; |
| 105 | + Xapi_pool.set_update_sync_enabled ~__context ~self ~value:true |
| 106 | + ) |
| 107 | + ) |
99 | 108 |
|
100 | 109 | let test =
|
101 | 110 | [
|
102 |
| - ( "test_set_remote_and_bundle_repos" |
103 |
| - , `Quick |
104 |
| - , test_set_remote_and_bundle_repos |
105 |
| - ) |
106 |
| - ; ("test_add_bundle_repo", `Quick, test_add_bundle_repo) |
107 |
| - ; ("test_add_remote_repo", `Quick, test_add_remote_repo) |
108 |
| - ; ( "test_can_not_enable_bundle_repo_auto_sync" |
109 |
| - , `Quick |
110 |
| - , test_can_not_enable_bundle_repo_auto_sync |
111 |
| - ) |
| 111 | + ("test_set_repositories", `Quick, test_set_repositories) |
| 112 | + ; ("test_add_repository", `Quick, test_add_repository) |
| 113 | + ; ("test_enable_periodic_repo_sync", `Quick, test_enable_periodic_repo_sync) |
112 | 114 | ]
|
113 | 115 |
|
114 | 116 | let () =
|
|
0 commit comments