Skip to content

Commit

Permalink
#1833 windows
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jan 21, 2025
1 parent 6a011da commit bb9e9ed
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class FfmpegStreamToStreamRunnerTests
private readonly string _ffmpegExePosix;
private readonly string _ffmpegExeWindows;
private readonly StorageHostFullPathFilesystem _hostFullPathFilesystem;
private readonly string _readFile;

public FfmpegStreamToStreamRunnerTests()
{
Expand All @@ -37,8 +36,7 @@ public FfmpegStreamToStreamRunnerTests()

_ffmpegExe = new AppSettings().IsWindows ? _ffmpegExeWindows : _ffmpegExePosix;

_readFile = Path.Combine(new CreateAnImage().BasePath,
"FfmpegStreamToStreamRunnerTests", "read_file");

}

private void CreateStubFile(string path, string content)
Expand All @@ -47,16 +45,19 @@ private void CreateStubFile(string path, string content)
_hostFullPathFilesystem.WriteStream(stream, path);
}

private async Task SetupFakeFfmpegExecutable()
private async Task<string> SetupFakeFfmpegExecutable(int i)
{
var readFile = Path.Combine(new CreateAnImage().BasePath,
"FfmpegStreamToStreamRunnerTests", "read_file.");

var zipper = Zipper.ExtractZip([
..
new CreateAnZipfileFakeFfMpeg().Bytes
]);

CreateStubFile(_ffmpegExePosix,
"#!/bin/bash\necho Fake Executable");
CreateStubFile(_readFile, "test_content");
CreateStubFile(readFile + i, "test_content");

var ffmpegExe = new MemoryStream(zipper.FirstOrDefault(p =>
p.Key == "ffmpeg.exe").Value);
Expand All @@ -67,6 +68,7 @@ await _hostFullPathFilesystem.WriteStreamAsync(ffmpegExe,
new FakeIWebLogger())
.Chmod(
_ffmpegExePosix);
return readFile + i;
}

[ClassCleanup]
Expand All @@ -77,14 +79,19 @@ public static void CleanUp()
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"ffmpeg.exe"));
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"read_file"));
"read_file.0"));
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"read_file.1"));
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"read_file.2"));
}

[TestMethod]
public async Task RunProcessAsync_HappyFlow()
{
await SetupFakeFfmpegExecutable();
var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(_readFile);
var readFile = await SetupFakeFfmpegExecutable(0);

var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(readFile);
var sut = new FfmpegStreamToStreamRunner(_ffmpegExe, file, new FakeIWebLogger());

var (stream, result) = await sut.RunProcessAsync("-1",
Expand All @@ -106,13 +113,13 @@ public async Task RunProcessAsync_ExitCode()
return;
}

await SetupFakeFfmpegExecutable();
var readFile = await SetupFakeFfmpegExecutable(1);

// overwrite the file with a bash script that will exit with code 1
CreateStubFile(_ffmpegExePosix,
"#!/bin/bash\ntest_content\n exit 1");

var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(_readFile);
var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(readFile);
var sut = new FfmpegStreamToStreamRunner(_ffmpegExe, file, new FakeIWebLogger());

var (stream, result) = await sut.RunProcessAsync("-1",
Expand All @@ -128,9 +135,9 @@ public async Task RunProcessAsync_ExitCode()
[TestMethod]
public async Task RunProcessAsync_WithInvalidFfmpegPath()
{
await SetupFakeFfmpegExecutable();
var readFile = await SetupFakeFfmpegExecutable(2);

var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(_readFile);
var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(readFile);
var sut = new FfmpegStreamToStreamRunner("invalid", file,
new FakeIWebLogger());

Expand Down

0 comments on commit bb9e9ed

Please sign in to comment.