51 lines
2.3 KiB
C#
51 lines
2.3 KiB
C#
using MoShiro.Measurement;
|
|
|
|
namespace MoShiro.Measurement.Tests;
|
|
|
|
public sealed class Ipv6DiagnosticsTests
|
|
{
|
|
[Fact]
|
|
public void Addresses_IgnoresLocalTentativeFailedAndDeprecatedAddresses()
|
|
{
|
|
Assert.Null(Ipv6Diagnostics.ParseAddresses(null));
|
|
Assert.False(Ipv6Diagnostics.ParseAddresses(""));
|
|
Assert.False(Ipv6Diagnostics.ParseAddresses("00000000000000000000000000000001 01 80 10 80 lo\nfe800000000000000000000000000001 02 40 20 80 eth0"));
|
|
foreach (string flags in new[] { "40", "08", "20" })
|
|
{
|
|
Assert.False(Ipv6Diagnostics.ParseAddresses($"20010db8000000000000000000000001 02 40 00 {flags} eth0"));
|
|
}
|
|
|
|
Assert.True(Ipv6Diagnostics.ParseAddresses("20010db8000000000000000000000001 02 40 00 80 eth0"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Routes_RequiresAnActiveNonLoopbackDefaultRoute()
|
|
{
|
|
Assert.Null(Ipv6Diagnostics.ParseRoutes(null));
|
|
Assert.False(Ipv6Diagnostics.ParseRoutes(""));
|
|
string prefix = "00000000000000000000000000000000 00 00000000000000000000000000000000 00 fe800000000000000000000000000001 00000400 00000000 00000000 ";
|
|
Assert.True(Ipv6Diagnostics.ParseRoutes(prefix + "00000003 eth0"));
|
|
Assert.False(Ipv6Diagnostics.ParseRoutes(prefix + "00000201 eth0"));
|
|
Assert.False(Ipv6Diagnostics.ParseRoutes(prefix + "00000001 lo"));
|
|
Assert.False(Ipv6Diagnostics.ParseRoutes(prefix + "00000000 eth0"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(false, true, true, true, "unsupported")]
|
|
[InlineData(true, true, false, true, "no_global_address")]
|
|
[InlineData(true, false, true, true, "not_listening")]
|
|
[InlineData(true, true, true, false, "no_default_route")]
|
|
[InlineData(true, true, true, true, "ready")]
|
|
public void Evaluate_DistinguishesConfigurationFromAddressAndRouting(bool supported, bool listening, bool address, bool route, string expected)
|
|
{
|
|
Assert.Equal(expected, Ipv6Diagnostics.Evaluate(supported, listening, address, route).State);
|
|
}
|
|
|
|
[Fact]
|
|
public void Probe_DoesNotRequireAnInboundListener_AndUnavailableDataStaysUnknown()
|
|
{
|
|
Assert.Equal("ready", Ipv6Diagnostics.Evaluate(true, null, true, true).State);
|
|
Assert.Equal("unknown", Ipv6Diagnostics.Evaluate(true, null, null, null).State);
|
|
}
|
|
}
|