amended testing unit.

pull/4125/head
Greenback 4 years ago
parent ec245dce90
commit 3e62557959

@ -19,6 +19,8 @@ namespace Jellyfin.Networking.Manager
{
/// <summary>
/// Class to take care of network interface management.
///
/// Note: The normal collection methods and properties will not work with NetCollection. <see cref="MediaBrowser.Common.Net.NetworkExtensions"/>.
/// </summary>
public class NetworkManager : INetworkManager, IDisposable
{
@ -925,8 +927,8 @@ namespace Jellyfin.Networking.Manager
// Read and parse bind addresses and exclusions, removing ones that don't exist.
_bindAddresses = CreateIPCollection(lanAddresses).Union(_interfaceAddresses);
_bindExclusions = CreateIPCollection(lanAddresses, true).Union(_interfaceAddresses);
_logger.LogInformation("Using bind addresses: {0}", _bindAddresses);
_logger.LogInformation("Using bind exclusions: {0}", _bindExclusions);
_logger.LogInformation("Using bind addresses: {0}", _bindAddresses.AsString());
_logger.LogInformation("Using bind exclusions: {0}", _bindExclusions.AsString());
}
private void InitialiseRemote(NetworkConfiguration config)
@ -997,9 +999,9 @@ namespace Jellyfin.Networking.Manager
_internalInterfaces = CreateCollection(_interfaceAddresses.Where(i => IsInLocalNetwork(i)));
}
_logger.LogInformation("Defined LAN addresses : {0}", _lanSubnets);
_logger.LogInformation("Defined LAN exclusions : {0}", _excludedSubnets);
_logger.LogInformation("Using LAN addresses: {0}", _lanSubnets.Exclude(_excludedSubnets).AsNetworks());
_logger.LogInformation("Defined LAN addresses : {0}", _lanSubnets.AsString());
_logger.LogInformation("Defined LAN exclusions : {0}", _excludedSubnets.AsString());
_logger.LogInformation("Using LAN addresses: {0}", _lanSubnets.Exclude(_excludedSubnets).AsNetworks().AsString());
}
}
@ -1090,7 +1092,7 @@ namespace Jellyfin.Networking.Manager
}
_logger.LogDebug("Discovered {0} interfaces.", _interfaceAddresses.Count);
_logger.LogDebug("Interfaces addresses : {0}", _interfaceAddresses);
_logger.LogDebug("Interfaces addresses : {0}", _interfaceAddresses.AsString());
// If for some reason we don't have an interface info, resolve our DNS name.
if (_interfaceAddresses.Count == 0)

@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Net
/// </summary>
/// <param name="source">The <see cref="NetCollection"/>.</param>
/// <returns>Returns a string representation of this object.</returns>
public static string Readable(this NetCollection source)
public static string AsString(this NetCollection source)
{
var sb = new StringBuilder();
string output = "[";

@ -71,7 +71,7 @@ namespace NetworkTesting
var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
NetworkManager.MockNetworkSettings = string.Empty;
Assert.True(string.Equals(nm.GetInternalBindAddresses().Readable(), value, StringComparison.Ordinal));
Assert.True(string.Equals(nm.GetInternalBindAddresses().AsString(), value, StringComparison.Ordinal));
}
[Theory]
@ -163,22 +163,22 @@ namespace NetworkTesting
// Test included, IP6.
NetCollection nc = nm.CreateIPCollection(settings.Split(","), false);
Assert.True(string.Equals(nc.Readable(), result1, System.StringComparison.OrdinalIgnoreCase));
Assert.True(string.Equals(nc?.AsString(), result1, System.StringComparison.OrdinalIgnoreCase));
// Text excluded, non IP6.
nc = nm.CreateIPCollection(settings.Split(","), true);
Assert.True(string.Equals(nc?.Readable(), result3, System.StringComparison.OrdinalIgnoreCase));
Assert.True(string.Equals(nc?.AsString(), result3, System.StringComparison.OrdinalIgnoreCase));
conf.EnableIPV6 = false;
nm.UpdateSettings(conf);
// Test included, non IP6.
nc = nm.CreateIPCollection(settings.Split(","), false);
Assert.True(string.Equals(nc.Readable(), result2, System.StringComparison.OrdinalIgnoreCase));
Assert.True(string.Equals(nc?.AsString(), result2, System.StringComparison.OrdinalIgnoreCase));
// Test excluded, including IPv6.
nc = nm.CreateIPCollection(settings.Split(","), true);
Assert.True(string.Equals(nc.Readable(), result4, System.StringComparison.OrdinalIgnoreCase));
Assert.True(string.Equals(nc?.AsString(), result4, System.StringComparison.OrdinalIgnoreCase));
conf.EnableIPV6 = true;
nm.UpdateSettings(conf);
@ -186,7 +186,7 @@ namespace NetworkTesting
// Test network addresses of collection.
nc = nm.CreateIPCollection(settings.Split(","), false);
nc = nc.AsNetworks();
Assert.True(string.Equals(nc.Readable(), result5, System.StringComparison.OrdinalIgnoreCase));
Assert.True(string.Equals(nc?.AsString(), result5, System.StringComparison.OrdinalIgnoreCase));
}
[Theory]
@ -205,7 +205,7 @@ namespace NetworkTesting
NetCollection nc1 = nm.CreateIPCollection(settings.Split(","), false);
NetCollection nc2 = nm.CreateIPCollection(compare.Split(","), false);
Assert.True(nc1.Union(nc2).Readable() == result);
Assert.True(nc1.Union(nc2).AsString() == result);
}
[Theory]

Loading…
Cancel
Save