Skip to content

Commit

Permalink
#1833 add extra coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jan 21, 2025
1 parent 95d4413 commit 4741793
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -178,4 +179,67 @@ public void IsFileReady_thumbnailStorage()

Assert.IsFalse(_thumbnailStorage.ExistFile(thumbnailId));
}

[TestMethod]
public void IsFolderOrFile()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.IsFolderOrFile("not-found"));
}

[TestMethod]
public void FolderMove()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.FolderMove("not-found", "2"));
}

[TestMethod]
public void CreateDirectory()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.CreateDirectory("not-found"));
}

[TestMethod]
public void FolderDelete()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.FolderDelete("not-found"));
}

[TestMethod]
public void GetAllFilesInDirectoryRecursive()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.GetAllFilesInDirectoryRecursive("not-found"));
}

[TestMethod]
public void GetDirectories()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.GetDirectories("not-found"));
}

[TestMethod]
public void GetDirectoryRecursive()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.GetDirectoryRecursive("not-found"));
}

[TestMethod]
public void ReadStream_NotFound()
{
Assert.ThrowsException<FileNotFoundException>(() =>
_thumbnailStorage.ReadStream("not-found"));
}

[TestMethod]
public void WriteStreamOpenOrCreate()
{
Assert.ThrowsException<NotSupportedException>(() =>
_thumbnailStorage.WriteStreamOpenOrCreate(Stream.Null, "not-found"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ namespace starskytest.starsky.foundation.video.Process;
public class FfmpegStreamToStreamRunnerTests
{
private readonly string _ffmpegExe;
private readonly string _ffmpegExePosix;
private readonly string _ffmpegExeWindows;
private readonly StorageHostFullPathFilesystem _hostFullPathFilesystem;
private readonly string _readFile;

public FfmpegStreamToStreamRunnerTests()
{
_hostFullPathFilesystem = new StorageHostFullPathFilesystem(new FakeIWebLogger());
if ( new AppSettings().IsWindows )
{
_ffmpegExe = new CreateAnImage().BasePath + "ffmpeg.exe";
}
else
{
_ffmpegExe = new CreateAnImage().BasePath + "ffmpeg";
}
_hostFullPathFilesystem.CreateDirectory(Path.Combine(new CreateAnImage().BasePath,
"FfmpegStreamToStreamRunnerTests"));

_ffmpegExeWindows = Path.Combine(new CreateAnImage().BasePath,
"FfmpegStreamToStreamRunnerTests", "ffmpeg.exe");
_ffmpegExePosix = Path.Combine(new CreateAnImage().BasePath,
"FfmpegStreamToStreamRunnerTests", "ffmpeg");

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

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

private void CreateStubFile(string path, string content)
Expand All @@ -50,27 +54,30 @@ private async Task SetupFakeFfmpegExecutable()
new CreateAnZipfileFakeFfMpeg().Bytes
]);

CreateStubFile(new CreateAnImage().BasePath + "ffmpeg",
CreateStubFile(_ffmpegExePosix,
"#!/bin/bash\necho Fake Executable");
CreateStubFile(_readFile, "test_content");

var ffmpegExe = new MemoryStream(zipper.FirstOrDefault(p =>
p.Key == "ffmpeg.exe").Value);
await _hostFullPathFilesystem.WriteStreamAsync(ffmpegExe,
new CreateAnImage().BasePath + "ffmpeg.exe");
_ffmpegExeWindows);

await new FfMpegChmod(new FakeSelectorStorage(_hostFullPathFilesystem),
new FakeIWebLogger())
.Chmod(
new CreateAnImage().BasePath + "ffmpeg");
_ffmpegExePosix);
}

[ClassCleanup]
public static void CleanUp()
{
File.Delete(new CreateAnImage().BasePath + "ffmpeg");
File.Delete(new CreateAnImage().BasePath + "ffmpeg.exe");
File.Delete(new CreateAnImage().BasePath + "read_file");
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"ffmpeg"));
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"ffmpeg.exe"));
File.Delete(Path.Combine(new CreateAnImage().BasePath, "FfmpegStreamToStreamRunnerTests",
"read_file"));
}

[TestMethod]
Expand Down Expand Up @@ -102,7 +109,7 @@ public async Task RunProcessAsync_ExitCode()
await SetupFakeFfmpegExecutable();

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

var file = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(_readFile);
Expand Down

0 comments on commit 4741793

Please sign in to comment.