Improve testability, packaging, and docs

This commit is contained in:
Vibe Myass
2026-03-16 03:45:00 +00:00
parent 775bb7813d
commit 458494221e
12 changed files with 565 additions and 110 deletions

View File

@@ -0,0 +1,41 @@
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);
}
}