diff options
Diffstat (limited to 'tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs')
| -rw-r--r-- | tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs b/tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs new file mode 100644 index 0000000..f55762e --- /dev/null +++ b/tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs @@ -0,0 +1,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) |
