summaryrefslogtreecommitdiff
path: root/tests/SomhairlesDream.Cli.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/SomhairlesDream.Cli.Tests')
-rw-r--r--tests/SomhairlesDream.Cli.Tests/ArgumentsTests.fs70
-rw-r--r--tests/SomhairlesDream.Cli.Tests/SomhairlesDream.Cli.Tests.fsproj21
2 files changed, 91 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)
diff --git a/tests/SomhairlesDream.Cli.Tests/SomhairlesDream.Cli.Tests.fsproj b/tests/SomhairlesDream.Cli.Tests/SomhairlesDream.Cli.Tests.fsproj
new file mode 100644
index 0000000..461d5eb
--- /dev/null
+++ b/tests/SomhairlesDream.Cli.Tests/SomhairlesDream.Cli.Tests.fsproj
@@ -0,0 +1,21 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <IsPackable>false</IsPackable>
+ <IsTestProject>true</IsTestProject>
+ </PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
+ <PackageReference Include="xunit" Version="2.9.2" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ </PackageReference>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="../../src/SomhairlesDream.Cli/SomhairlesDream.Cli.fsproj" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ArgumentsTests.fs" />
+ </ItemGroup>
+</Project>