Rename get_builds_and_exclude_the_first

This commit is contained in:
Robur 2024-01-09 12:05:24 +00:00 committed by Reynir Björnsson
parent 73e1bf81ce
commit 6594c6b912
3 changed files with 9 additions and 9 deletions

View file

@ -365,7 +365,7 @@ module Build = struct
ORDER BY b.start_d DESC, b.start_ps DESC
|}
let get_builds_and_exclude_the_first =
let get_builds_excluding_latest_n =
Caqti_type.(tup3 (id `job) (option string) int) ->* Caqti_type.tup2 t file @@
{| SELECT b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps,
b.result_code, b.result_msg, b.console, b.script,

View file

@ -131,7 +131,7 @@ sig
Caqti_request.t
val get_builds_older_than :
([`job] id * string option * Ptime.t, t * file, [ `Many | `One | `Zero ]) Caqti_request.t
val get_builds_and_exclude_the_first :
val get_builds_excluding_latest_n :
([`job] id * string option * int, t * file, [ `Many | `One | `Zero ]) Caqti_request.t
val get_previous_successful_different_output :
([`build] id, t, [ `One | `Zero ])

View file

@ -289,22 +289,22 @@ let test_get_builds_older_than (module Db : CONN) =
Alcotest.(check (list Testable.uuid)) "last builds" builds [ uuid'; uuid ];
Ok ()
let test_builds_and_exclude_the_first (module Db : CONN) =
let test_builds_excluding_latest_n (module Db : CONN) =
add_second_build (module Db) >>= fun () ->
Db.find_opt Builder_db.Job.get_id_by_name job_name >>= fail_if_none >>= fun job_id ->
Db.collect_list Builder_db.Build.get_builds_and_exclude_the_first (job_id, None, 1) >>= fun builds ->
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 1) >>= fun builds ->
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
Alcotest.(check (list Testable.uuid)) "keep recent build" builds [ uuid ];
Db.collect_list Builder_db.Build.get_builds_and_exclude_the_first (job_id, None, 2) >>= fun builds ->
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 2) >>= fun builds ->
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
Alcotest.(check (list Testable.uuid)) "keep 2 builds" builds [];
Db.collect_list Builder_db.Build.get_builds_and_exclude_the_first (job_id, None, 3) >>= fun builds ->
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 3) >>= fun builds ->
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
Alcotest.(check (list Testable.uuid)) "last more builds than we have" builds [];
Db.collect_list Builder_db.Build.get_builds_and_exclude_the_first (job_id, None, 0) >>= fun builds ->
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 0) >>= fun builds ->
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
Alcotest.(check (list Testable.uuid)) "delete all builds" builds [ uuid'; uuid ];
Db.collect_list Builder_db.Build.get_builds_and_exclude_the_first (job_id, None, -1) >>= fun builds ->
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, -1) >>= fun builds ->
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
Alcotest.(check (list Testable.uuid)) "test an incomprehensible argument (-1)" builds [ uuid'; uuid ];
Ok ()
@ -345,6 +345,6 @@ let () =
];
"vacuum", [
test_case "Get builds older than now" `Quick (with_build_db test_get_builds_older_than);
test_case "Get older builds and keep a fixed number of then" `Quick (with_build_db test_builds_and_exclude_the_first);
test_case "Get older builds and keep a fixed number of then" `Quick (with_build_db test_builds_excluding_latest_n);
]
]