Skip to content

Commit

Permalink
CP-49212: Add UT for update datamodel for non-CDN update
Browse files Browse the repository at this point in the history
Signed-off-by: Bengang Yuan <[email protected]>
  • Loading branch information
BengangY committed Jul 11, 2024
1 parent ae62779 commit 9af8b57
Showing 1 changed file with 96 additions and 9 deletions.
105 changes: 96 additions & 9 deletions ocaml/tests/test_repository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

module T = Test_common

let test_introduce_duplicate_name () =
let test_introduce_duplicate_remote_repo () =
let __context = T.make_test_database () in
let name_label = "name" in
let name_description = "description" in
Expand All @@ -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"
Alcotest.check_raises "test_introduce_duplicate_remote_repo"
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
)

Expand All @@ -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
)

Expand All @@ -67,25 +69,94 @@ 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
Alcotest.check_raises "test_introduce_invalid_gpgkey_path_2"
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_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_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_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_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
)

let test =
[
("test_introduce_duplicate_name", `Quick, test_introduce_duplicate_name)
( "test_introduce_duplicate_remote_repo"
, `Quick
, test_introduce_duplicate_remote_repo
)
; ( "test_introduce_duplicate_binary_url"
, `Quick
, test_introduce_duplicate_binary_url
Expand All @@ -94,6 +165,22 @@ let test =
, `Quick
, test_introduce_invalid_gpgkey_path
)
; ( "test_introduce_duplicate_bundle_repo"
, `Quick
, test_introduce_duplicate_bundle_repo
)
; ( "test_introduce_bundle_repo_binary_url_not_empty"
, `Quick
, test_introduce_bundle_repo_binary_url_not_empty
)
; ( "test_introduce_bundle_repo_source_url_not_empty"
, `Quick
, test_introduce_bundle_repo_source_url_not_empty
)
; ( "test_introduce_bundle_repo_update_is_false"
, `Quick
, test_introduce_bundle_repo_update_is_false
)
]

let () =
Expand Down

0 comments on commit 9af8b57

Please sign in to comment.