Skip to content

Commit 5dabcb7

Browse files
Fixed executable path in tests.
1 parent 382358d commit 5dabcb7

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

ConvertApi.Cli.Tests/CliTests.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace ConvertApi.Cli.Tests;
55
[TestFixture]
66
public class CliTests
77
{
8-
private static readonly string CliExecutablePath = Path.Combine(Directory.GetCurrentDirectory(), "convertapi-cli.exe");
98
private const string ApiToken = "token_ST4z2qhE"; // Provide your API token
109
private static readonly string TestOutputDir = Path.Combine(Directory.GetCurrentDirectory(), "test_output");
1110

@@ -67,14 +66,15 @@ public void TestProtectPdfWithPassword()
6766

6867
private Process RunCli(string arguments)
6968
{
70-
if (!File.Exists(CliExecutablePath))
71-
throw new FileNotFoundException($"CLI executable not found at {CliExecutablePath}");
69+
var cliExecutablePath = GetCliExecutablePath();
70+
if (!File.Exists(cliExecutablePath))
71+
throw new FileNotFoundException($"CLI executable not found at {cliExecutablePath}");
7272

7373
var process = new Process
7474
{
7575
StartInfo = new ProcessStartInfo
7676
{
77-
FileName = CliExecutablePath,
77+
FileName = cliExecutablePath,
7878
Arguments = arguments,
7979
UseShellExecute = true, // Run in a normal console environment, because otherwise process hangs because of readline in program.cs
8080
CreateNoWindow = true
@@ -96,4 +96,25 @@ private Process RunCli(string arguments)
9696

9797
return process;
9898
}
99+
100+
private string GetCliExecutablePath()
101+
{
102+
var executableName = Path.Combine(Directory.GetCurrentDirectory(), "convertapi-cli");
103+
if (OperatingSystem.IsWindows())
104+
{
105+
executableName += ".exe";
106+
}
107+
108+
var path = Path.Combine(
109+
AppContext.BaseDirectory,
110+
executableName
111+
);
112+
113+
if (!File.Exists(path))
114+
{
115+
throw new FileNotFoundException($"CLI executable not found at {path}");
116+
}
117+
118+
return path;
119+
}
99120
}

0 commit comments

Comments
 (0)