From 0aec86b089b26d9a98631dd486bf551d149328cc Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Mon, 1 Jul 2024 13:58:44 +0800 Subject: [PATCH] CP-49212: Add UT for update datamodel for non-CDN update Signed-off-by: Bengang Yuan --- ocaml/tests/test_repository.ml | 96 +++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 6 deletions(-) diff --git a/ocaml/tests/test_repository.ml b/ocaml/tests/test_repository.ml index e30cf71362a..71a5f89f956 100644 --- a/ocaml/tests/test_repository.ml +++ b/ocaml/tests/test_repository.ml @@ -24,16 +24,17 @@ let test_introduce_duplicate_name () = let source_url = "https://repo-src.example.com" in let source_url_1 = "https://repo-src1.example.com" in let gpgkey_path = "" in + let origin = `remote in let ref = Repository.introduce ~__context ~name_label ~name_description ~binary_url - ~source_url ~update:true ~gpgkey_path + ~source_url ~update:true ~gpgkey_path ~origin in Alcotest.check_raises "test_introduce_duplicate_name" Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref])) (fun () -> Repository.introduce ~__context ~name_label ~name_description:name_description_1 ~binary_url:binary_url_1 - ~source_url:source_url_1 ~update:true ~gpgkey_path + ~source_url:source_url_1 ~update:true ~gpgkey_path ~origin |> ignore ) @@ -47,16 +48,17 @@ let test_introduce_duplicate_binary_url () = let source_url = "https://repo-src.example.com" in let source_url_1 = "https://repo-src1.example.com" in let gpgkey_path = "" in + let origin = `remote in let ref = Repository.introduce ~__context ~name_label ~name_description ~binary_url - ~source_url ~update:true ~gpgkey_path + ~source_url ~update:true ~gpgkey_path ~origin in Alcotest.check_raises "test_introduce_duplicate_name" Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref])) (fun () -> Repository.introduce ~__context ~binary_url ~name_label:name_label_1 ~name_description:name_description_1 ~source_url:source_url_1 - ~update:false ~gpgkey_path + ~update:false ~gpgkey_path ~origin |> ignore ) @@ -67,11 +69,12 @@ let test_introduce_invalid_gpgkey_path () = let binary_url = "https://repo.example.com" in let source_url = "https://repo-src.example.com" in let gpgkey_path_1 = "../some-file" in + let origin = `remote in Alcotest.check_raises "test_introduce_invalid_gpgkey_path_1" Api_errors.(Server_error (Api_errors.invalid_gpgkey_path, [gpgkey_path_1])) (fun () -> Repository.introduce ~__context ~binary_url ~name_label ~name_description - ~source_url ~update:false ~gpgkey_path:gpgkey_path_1 + ~source_url ~update:false ~gpgkey_path:gpgkey_path_1 ~origin |> ignore ) ; let gpgkey_path_2 = "some.file" in @@ -79,7 +82,72 @@ let test_introduce_invalid_gpgkey_path () = Api_errors.(Server_error (Api_errors.invalid_gpgkey_path, [gpgkey_path_2])) (fun () -> Repository.introduce ~__context ~binary_url ~name_label ~name_description - ~source_url ~update:false ~gpgkey_path:gpgkey_path_2 + ~source_url ~update:false ~gpgkey_path:gpgkey_path_2 ~origin + |> ignore + ) + +let test_introduce_duplicate_bundle_repo () = + let __context = T.make_test_database () in + let name_label = "name" in + let name_label_1 = "name1" in + let name_description = "description" in + let name_description_1 = "description1" in + let gpgkey_path = "" in + let origin = `bundle in + let ref = + Repository.introduce ~__context ~name_label ~name_description ~binary_url:"" + ~source_url:"" ~update:true ~gpgkey_path ~origin + in + Alcotest.check_raises "test_introduce_duplicate_bundle_repo" + Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref])) + (fun () -> + Repository.introduce ~__context ~name_label:name_label_1 + ~name_description:name_description_1 ~binary_url:"" ~source_url:"" + ~update:true ~gpgkey_path ~origin + |> ignore + ) + +let test_introduce_bundle_repo_url_binary_url_not_empty () = + let __context = T.make_test_database () in + let name_label = "name" in + let name_description = "description" in + let gpgkey_path = "" in + let origin = `bundle in + Alcotest.check_raises "test_introduce_bundle_repo_url_binary_url_not_empty" + Api_errors.(Server_error (bundle_repo_url_should_be_empty, [])) + (fun () -> + Repository.introduce ~__context ~name_label ~name_description + ~binary_url:"http://test.url" ~source_url:"" ~update:true ~gpgkey_path + ~origin + |> ignore + ) + +let test_introduce_bundle_repo_url_source_url_not_empty () = + let __context = T.make_test_database () in + let name_label = "name" in + let name_description = "description" in + let gpgkey_path = "" in + let origin = `bundle in + Alcotest.check_raises "test_introduce_bundle_repo_url_source_url_not_empty" + Api_errors.(Server_error (bundle_repo_url_should_be_empty, [])) + (fun () -> + Repository.introduce ~__context ~name_label ~name_description + ~binary_url:"" ~source_url:"http://test.url" ~update:true ~gpgkey_path + ~origin + |> ignore + ) + +let test_introduce_bundle_repo_update_is_false () = + let __context = T.make_test_database () in + let name_label = "name" in + let name_description = "description" in + let gpgkey_path = "" in + let origin = `bundle in + Alcotest.check_raises "test_introduce_bundle_repo_update_is_false" + Api_errors.(Server_error (bundle_repo_update_should_be_true, [])) + (fun () -> + Repository.introduce ~__context ~name_label ~name_description + ~binary_url:"" ~source_url:"" ~update:false ~gpgkey_path ~origin |> ignore ) @@ -94,6 +162,22 @@ let test = , `Quick , test_introduce_invalid_gpgkey_path ) + ; ( "test_introduce_duplicate_bundle_repo" + , `Quick + , test_introduce_duplicate_bundle_repo + ) + ; ( "test_introduce_bundle_repo_url_binary_url_not_empty" + , `Quick + , test_introduce_bundle_repo_url_binary_url_not_empty + ) + ; ( "test_introduce_bundle_repo_url_source_url_not_empty" + , `Quick + , test_introduce_bundle_repo_url_source_url_not_empty + ) + ; ( "test_introduce_bundle_repo_update_is_false" + , `Quick + , test_introduce_bundle_repo_update_is_false + ) ] let () =