Skip to content

Commit

Permalink
test: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Dec 6, 2024
1 parent 0d859b1 commit d0142b3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/HuskyTest/Cli/ExecCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Immutable;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Reflection;
using System.Text;
using CliFx.Exceptions;
using CliFx.Infrastructure;
using FluentAssertions;
Expand Down Expand Up @@ -145,13 +145,15 @@ public async Task Exec_CachedScript_ShouldThrowWithNonZeroExitCode()
const string filePath = "fake_file.csx";
const string stringContent = @"
return 1;
";
";

_io.Path.GetDirectoryName(Arg.Any<string>()).Returns(Directory.GetCurrentDirectory());
_io.File.Exists(Arg.Any<string>()).Returns(true);
_io.Directory.Exists(Arg.Any<string>()).Returns(true);
_io.File.ReadAllTextAsync(Arg.Any<string>()).Returns(stringContent);
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(stringContent));
_io.FileStream.Create(Arg.Any<string>(), FileMode.Open).Returns(stream);

var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filePath, new MockFileData(stringContent) } });
_io.FileStream.New(filePath, FileMode.Open).Returns(mockFileSystem.File.Create(filePath));

var opts = ScriptOptions.Default
.WithSourceResolver(new SourceFileResolver(ImmutableArray<string>.Empty, null))
Expand All @@ -160,7 +162,7 @@ public async Task Exec_CachedScript_ShouldThrowWithNonZeroExitCode()
var compilation = script.GetCompilation();

await using var assemblyStream = new MemoryStream();
var _ = compilation.Emit(assemblyStream);
_ = compilation.Emit(assemblyStream);
_assembly.LoadFile(Arg.Any<string>()).Returns(Assembly.Load(assemblyStream.ToArray()));

var command = new ExecCommand(_io, _git, _assembly) { Path = filePath, Arguments = new List<string> { "test" }, NoCache = false };
Expand Down

0 comments on commit d0142b3

Please sign in to comment.