42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
namespace LibNftables.Tests;
|
|
|
|
public sealed class NftErrorTranslatorTests
|
|
{
|
|
[Fact]
|
|
public void PermissionErrors_AreClassified()
|
|
{
|
|
NftException ex = NftErrorTranslator.FromOperationFailure("RunCommand", 1, "Operation not permitted");
|
|
|
|
Assert.IsType<NftPermissionException>(ex);
|
|
Assert.Equal(1, ex.NativeErrorCode);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidationErrors_AreClassified()
|
|
{
|
|
NftException ex = NftErrorTranslator.FromOperationFailure("RunCommand", 2, "syntax error, unexpected token");
|
|
|
|
Assert.IsType<NftValidationException>(ex);
|
|
Assert.Equal(2, ex.NativeErrorCode);
|
|
}
|
|
|
|
[Fact]
|
|
public void UnsupportedErrors_AreClassified()
|
|
{
|
|
NftException ex = NftErrorTranslator.FromOperationFailure("RunCommand", 3, "operation not supported");
|
|
|
|
Assert.IsType<NftUnsupportedException>(ex);
|
|
Assert.Equal(3, ex.NativeErrorCode);
|
|
}
|
|
|
|
[Fact]
|
|
public void UnknownErrors_FallBackToBaseException()
|
|
{
|
|
NftException ex = NftErrorTranslator.FromOperationFailure("RunCommand", 4, "unexpected native failure");
|
|
|
|
Assert.IsType<NftException>(ex);
|
|
Assert.Equal(4, ex.NativeErrorCode);
|
|
Assert.DoesNotContain("syntax error", ex.Message, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|