Complete typed map ergonomics and preview API
This commit is contained in:
@@ -29,6 +29,27 @@ public sealed class NftRulesetRendererTests
|
||||
Assert.Contains("443 : drop", rendered, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Render_WithIncompatibleTypedMapKey_ThrowsValidationException()
|
||||
{
|
||||
var ruleset = new NftRuleset();
|
||||
var table = new NftTable
|
||||
{
|
||||
Name = "filter",
|
||||
};
|
||||
var map = new NftMap
|
||||
{
|
||||
Name = "bad_map",
|
||||
KeyType = NftMapType.InetService,
|
||||
ValueType = NftMapType.Verdict,
|
||||
};
|
||||
map.Add(NftValue.Interface("eth0"), NftValue.Verdict(NftVerdict.Accept));
|
||||
table.Maps.Add(map);
|
||||
ruleset.Tables.Add(table);
|
||||
|
||||
Assert.Throws<NftValidationException>(() => NftRulesetRenderer.Render(ruleset));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Render_WithNoTables_ThrowsValidationException()
|
||||
{
|
||||
@@ -130,16 +151,8 @@ public sealed class NftRulesetRendererTests
|
||||
KeyType = NftMapType.InetService,
|
||||
ValueType = NftMapType.Verdict,
|
||||
};
|
||||
map.Entries.Add(new NftMapEntry
|
||||
{
|
||||
Key = NftValue.Port(80),
|
||||
Value = NftValue.Verdict(NftVerdict.Accept),
|
||||
});
|
||||
map.Entries.Add(new NftMapEntry
|
||||
{
|
||||
Key = NftValue.Port(443),
|
||||
Value = NftValue.Verdict(NftVerdict.Drop),
|
||||
});
|
||||
map.Add(NftValue.Port(80), NftValue.Verdict(NftVerdict.Accept));
|
||||
map.Add(NftValue.Port(443), NftValue.Verdict(NftVerdict.Drop));
|
||||
table.Maps.Add(map);
|
||||
|
||||
var chain = new NftChain
|
||||
|
||||
Reference in New Issue
Block a user