tests
This commit is contained in:
parent
9ce06e4639
commit
68b01dd287
2 changed files with 5 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
(library
|
(library
|
||||||
(name pam)
|
(name pam)
|
||||||
(libraries riot ptime str)
|
(libraries riot ptime str yojson batteries)
|
||||||
(preprocess
|
(preprocess
|
||||||
(pps lwt_ppx ppx_string ))
|
(pps lwt_ppx ppx_string ))
|
||||||
)
|
)
|
|
@ -25,14 +25,14 @@ let test_parse () =
|
||||||
"2024-04-18T10:00:00+02:00" ;
|
"2024-04-18T10:00:00+02:00" ;
|
||||||
"2024-04-23T23:00:00+02:00" ;
|
"2024-04-23T23:00:00+02:00" ;
|
||||||
] |> List.map (fun e -> e |> Ptime.of_rfc3339 |> Result.get_ok |> function | t, _, _ -> t) in
|
] |> List.map (fun e -> e |> Ptime.of_rfc3339 |> Result.get_ok |> function | t, _, _ -> t) in
|
||||||
let res = Pam.Issue_parser.to_datetime reminder in
|
let res = Pam.Issuelib.to_datetime reminder in
|
||||||
match res with
|
match res with
|
||||||
| Ok None -> Alcotest.fail "Got Ok None"
|
| Ok None -> Alcotest.fail "Got Ok None"
|
||||||
| Error e -> Alcotest.fail [%string "Got Error %{e}"]
|
| Error e -> Alcotest.fail [%string "Got Error %{e}"]
|
||||||
| Ok (Some got) -> Alcotest.check (list ptime_testable) "Alert times" expected got
|
| Ok (Some got) -> Alcotest.check (list ptime_testable) "Alert times" expected got
|
||||||
|
|
||||||
let test_fire () =
|
let test_fire () =
|
||||||
let should_alert (lst, now) = Pam.Issue_parser.should_alert lst now in
|
let should_alert (lst, now) = Pam.Issuelib.should_alert now lst in
|
||||||
let of_rfc x = x |> Ptime.of_rfc3339 |> Result.get_ok |> function | t, _, _ -> t in
|
let of_rfc x = x |> Ptime.of_rfc3339 |> Result.get_ok |> function | t, _, _ -> t in
|
||||||
let transform (lst, clock) = (List.map of_rfc lst, of_rfc clock) in
|
let transform (lst, clock) = (List.map of_rfc lst, of_rfc clock) in
|
||||||
let alerts0 = (["2024-04-19T12:38:00+02:00"], "2024-04-19T06:38:00-04:00") |> transform in
|
let alerts0 = (["2024-04-19T12:38:00+02:00"], "2024-04-19T06:38:00-04:00") |> transform in
|
||||||
|
@ -42,6 +42,7 @@ let test_fire () =
|
||||||
let alerts4 = (["2024-04-20T10:02:00+02:00"], "2024-04-22T12:00:00+02:00") |> transform in
|
let alerts4 = (["2024-04-20T10:02:00+02:00"], "2024-04-22T12:00:00+02:00") |> transform in
|
||||||
let alerts5 = (["2024-04-20T10:02:00+02:00" ; "2024-05-20T10:02:00+02:00"], "2024-04-22T12:00:00+02:00") |> transform in
|
let alerts5 = (["2024-04-20T10:02:00+02:00" ; "2024-05-20T10:02:00+02:00"], "2024-04-22T12:00:00+02:00") |> transform in
|
||||||
let alerts6 = (["2024-04-20T10:02:00+02:00" ; "2024-05-20T10:02:00+02:00"], "2024-04-22T12:00:00+00:00") |> transform in
|
let alerts6 = (["2024-04-20T10:02:00+02:00" ; "2024-05-20T10:02:00+02:00"], "2024-04-22T12:00:00+00:00") |> transform in
|
||||||
|
let alerts7 = (["2024-04-19T12:38:00+02:00"], "2024-04-19T06:38:32-04:00") |> transform in
|
||||||
(
|
(
|
||||||
Alcotest.check (bool) "exact moment" true ( should_alert alerts0 ) ;
|
Alcotest.check (bool) "exact moment" true ( should_alert alerts0 ) ;
|
||||||
Alcotest.check (bool) "alert is in the future" false ( should_alert alerts1 ) ;
|
Alcotest.check (bool) "alert is in the future" false ( should_alert alerts1 ) ;
|
||||||
|
@ -50,6 +51,7 @@ let test_fire () =
|
||||||
Alcotest.check (bool) "alert is in the past but it is non-utc noon" false ( should_alert alerts4 ) ;
|
Alcotest.check (bool) "alert is in the past but it is non-utc noon" false ( should_alert alerts4 ) ;
|
||||||
Alcotest.check (bool) "one alert in the past, one in the future" false ( should_alert alerts5 ) ;
|
Alcotest.check (bool) "one alert in the past, one in the future" false ( should_alert alerts5 ) ;
|
||||||
Alcotest.check (bool) "one alert in the past, one in the future, it is noon" false ( should_alert alerts6 ) ;
|
Alcotest.check (bool) "one alert in the past, one in the future, it is noon" false ( should_alert alerts6 ) ;
|
||||||
|
Alcotest.check (bool) "same time, different seconds" true ( should_alert alerts7 ) ;
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue