Bidello/tests/UnitTest1.fs

98 lines
2.2 KiB
Forth
Raw Normal View History

2024-10-26 14:12:05 +02:00
module tests
open NUnit.Framework
open Pentole.TestsExtensions
2024-10-28 19:33:36 +01:00
open Bidello.Datatypes
open Bidello
open Pentole.String
2024-10-26 14:12:05 +02:00
2024-11-06 15:32:32 +01:00
let now = NodaTime.SystemClock.Instance.GetCurrentInstant ()
2024-10-26 14:12:05 +02:00
[<Test>]
2024-10-28 19:33:36 +01:00
let string_prefix_active_pattern () =
match "@after job" with
2024-11-06 15:32:32 +01:00
| Prefix "@after" _ -> Assert.Pass ()
2024-10-28 19:33:36 +01:00
| _ -> Assert.Pass ()
match "@after job " with
| Prefix "@after" j -> Assert.Pass ()
| _ -> Assert.Pass ()
let bj =
{ job_name = "j1"
hostname = "h1"
``when`` = "* * * * *"
executable = "echo"
workdir = "/"; user = "nobody"
args = [||]; environment = "";
done_at = None }
2024-11-06 15:32:32 +01:00
let run_function x =
let reduce (cj: CronJob) = (cj.hostname, cj.job_name)
Cron.sort_cron_jobs now x
|> Result.map (List.map (List.map reduce))
|> Pentole.Result.get
[<Test>]
let job_deps_simple () =
let requirements = [bj]
let cjs = run_function requirements
let expected = [[("h1", "j1")]]
Assert.are_seq_equal expected cjs
2024-10-28 19:33:36 +01:00
[<Test>]
let job_deps () =
let requirements = [
bj
{bj with job_name = "j2"}
{bj with hostname = "h2"}
{bj with job_name = "j1_after"; ``when``="@after j1"}
]
2024-11-06 15:32:32 +01:00
let cjs = run_function requirements
let expected = [[("h1", "j1"); ("h1", "j1_after")]; [("h2", "j1")]; [("h1", "j2")]]
Assert.are_seq_equal expected cjs
[<Test>]
let job_deps2 () =
let requirements = [
bj
{bj with job_name = "j2"}
{bj with hostname = "h2"}
{bj with job_name = "j1_after"; ``when``="@after j1"}
{bj with job_name = "j2_after"; ``when``="@after j2"}
]
let cjs = run_function requirements
let expected = [[("h1", "j1"); ("h1", "j1_after")];
[("h1", "j2"); ("h1", "j2_after")];
[("h2", "j1")]]
Assert.are_seq_equal expected cjs
[<Test>]
let should_fail_no_host () =
let requirements = [
bj
{bj with job_name = "j2"}
{bj with hostname = "h2"}
{bj with job_name = "j1_after"; ``when``="@after j1"; hostname="nope"}
{bj with job_name = "j2_after"; ``when``="@after j2"}
]
2024-10-28 19:33:36 +01:00
2024-11-06 15:32:32 +01:00
Cron.sort_cron_jobs now requirements
|> Result.isError
|> Assert.is_true