summaryrefslogtreecommitdiff
path: root/tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs
blob: f55762e44de617c3c7590f7e8a9d00c3448a0474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module SomhairlesDream.Cli.Tests.ArgumentsTests

open Xunit
open SomhairlesDream.Cli

let private expectOk = function
    | Ok value -> value
    | Error message -> failwith message

let private expectError = function
    | Error message -> message
    | Ok _ -> failwith "expected an error"

[<Fact>]
let ``run command applies documented defaults`` () =
    match Arguments.parse [| "run" |] |> expectOk with
    | Run options ->
        Assert.Equal("heritage-001", options.Ids.ProjectId)
        Assert.Equal("run-001", options.Ids.RunId)
        Assert.Equal("base-000", options.Ids.BaseId)
        Assert.Equal("target-003", options.Ids.TargetId)
        Assert.Equal(".artifacts", options.OutputRoot)
        Assert.Equal("stage", options.StageRoot)
        Assert.False(options.Render)
        Assert.NotEmpty(options.Python)
    | Verify _
    | Help -> failwith "expected run command"

[<Fact>]
let ``run command parses explicit ids and render flag`` () =
    match
        Arguments.parse
            [| "run"
               "--project-id"
               "project-x"
               "--run-id"
               "run-x"
               "--base-id"
               "base-x"
               "--target-id"
               "target-x"
               "--output-root"
               "out"
               "--stage-root"
               "fixtures"
               "--python"
               "/tmp/python"
               "--render" |]
        |> expectOk with
    | Run options ->
        Assert.Equal("project-x", options.Ids.ProjectId)
        Assert.Equal("run-x", options.Ids.RunId)
        Assert.Equal("base-x", options.Ids.BaseId)
        Assert.Equal("target-x", options.Ids.TargetId)
        Assert.Equal("out", options.OutputRoot)
        Assert.Equal("fixtures", options.StageRoot)
        Assert.Equal("/tmp/python", options.Python)
        Assert.True(options.Render)
    | Verify _
    | Help -> failwith "expected run command"

[<Fact>]
let ``verify command requires exactly one manifest path`` () =
    match Arguments.parse [| "verify"; "run"; "extra" |] |> expectError with
    | message -> Assert.Contains("manifest", message)

[<Fact>]
let ``arguments reject unsafe resource ids`` () =
    match Arguments.parse [| "run"; "--project-id"; "../escape" |] |> expectError with
    | message -> Assert.Contains("resource id", message)