58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
|
|
// Copyright (c) The Geekeey Authors
|
||
|
|
// SPDX-License-Identifier: EUPL-1.2
|
||
|
|
|
||
|
|
using Geekeey.Process.Buffered;
|
||
|
|
|
||
|
|
namespace Geekeey.Process.Tests;
|
||
|
|
|
||
|
|
internal sealed class ValidationTests
|
||
|
|
{
|
||
|
|
private static Command Exit()
|
||
|
|
{
|
||
|
|
return new Command(Testing.Fixture.Program.FilePath)
|
||
|
|
.WithArguments(["exit", "1"]);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public async Task I_can_try_to_execute_a_command_and_get_an_error_if_it_returns_a_non_zero_exit_code()
|
||
|
|
{
|
||
|
|
// Arrange
|
||
|
|
var cmd = Exit();
|
||
|
|
|
||
|
|
// Act & Assert
|
||
|
|
await Assert.That(async () => await cmd.ExecuteAsync()).Throws<CommandExecutionException>().And
|
||
|
|
.Member(static exception => exception.Message, static source => source.Contains("a non-zero exit code (1)")).And
|
||
|
|
.Member(static exception => exception.ExitCode, static source => source.IsEqualTo(1));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public async Task I_can_try_to_execute_a_command_with_buffering_and_get_a_detailed_error_if_it_returns_a_non_zero_exit_code()
|
||
|
|
{
|
||
|
|
// Arrange
|
||
|
|
var cmd = Exit();
|
||
|
|
|
||
|
|
|
||
|
|
// Act & Assert
|
||
|
|
await Assert.That(async () => await cmd.ExecuteBufferedAsync()).Throws<CommandExecutionException>().And
|
||
|
|
.Member(static exception => exception.Message, static source => source.Contains("Exit code set to 1")).And
|
||
|
|
.Member(static exception => exception.ExitCode, static source => source.IsEqualTo(1));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public async Task I_can_execute_a_command_without_validating_the_exit_code()
|
||
|
|
{
|
||
|
|
// Arrange
|
||
|
|
var cmd = Exit()
|
||
|
|
.WithExitValidation(ValidationMode.None);
|
||
|
|
|
||
|
|
// Act
|
||
|
|
var result = await cmd.ExecuteAsync();
|
||
|
|
|
||
|
|
// Assert
|
||
|
|
using (Assert.Multiple())
|
||
|
|
{
|
||
|
|
await Assert.That(result.ExitCode).IsEqualTo(1);
|
||
|
|
await Assert.That(result.IsSuccess).IsFalse();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|