audit notes work completed, test fixes work (95% done), new sprints, new data sources setup and configuration
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
using StellaOps.DistroIntel;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.DistroIntel.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for DerivativeConfidence enum.
|
||||
/// </summary>
|
||||
public sealed class DerivativeConfidenceTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(DerivativeConfidence.High)]
|
||||
[InlineData(DerivativeConfidence.Medium)]
|
||||
public void DerivativeConfidence_AllValues_AreDefined(DerivativeConfidence confidence)
|
||||
{
|
||||
Assert.True(Enum.IsDefined(confidence));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DerivativeConfidence_AllValues_AreCounted()
|
||||
{
|
||||
var values = Enum.GetValues<DerivativeConfidence>();
|
||||
Assert.Equal(2, values.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for DistroDerivative record.
|
||||
/// </summary>
|
||||
public sealed class DistroDerivativeTests
|
||||
{
|
||||
[Fact]
|
||||
public void DistroDerivative_RequiredProperties_MustBeSet()
|
||||
{
|
||||
var derivative = new DistroDerivative("rhel", "almalinux", 9, DerivativeConfidence.High);
|
||||
|
||||
Assert.Equal("rhel", derivative.CanonicalDistro);
|
||||
Assert.Equal("almalinux", derivative.DerivativeDistro);
|
||||
Assert.Equal(9, derivative.MajorRelease);
|
||||
Assert.Equal(DerivativeConfidence.High, derivative.Confidence);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DistroDerivative_RecordEquality_WorksCorrectly()
|
||||
{
|
||||
var d1 = new DistroDerivative("rhel", "rocky", 9, DerivativeConfidence.High);
|
||||
var d2 = new DistroDerivative("rhel", "rocky", 9, DerivativeConfidence.High);
|
||||
|
||||
Assert.Equal(d1, d2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DistroDerivative_DifferentReleases_AreNotEqual()
|
||||
{
|
||||
var d1 = new DistroDerivative("rhel", "rocky", 8, DerivativeConfidence.High);
|
||||
var d2 = new DistroDerivative("rhel", "rocky", 9, DerivativeConfidence.High);
|
||||
|
||||
Assert.NotEqual(d1, d2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for DistroMappings static class.
|
||||
/// </summary>
|
||||
public sealed class DistroMappingsTests
|
||||
{
|
||||
[Fact]
|
||||
public void DistroMappings_Derivatives_ContainsKnownMappings()
|
||||
{
|
||||
Assert.NotEmpty(DistroMappings.Derivatives);
|
||||
Assert.True(DistroMappings.Derivatives.Length >= 10);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("rhel", 8)]
|
||||
[InlineData("rhel", 9)]
|
||||
[InlineData("debian", 11)]
|
||||
[InlineData("debian", 12)]
|
||||
[InlineData("ubuntu", 20)]
|
||||
[InlineData("ubuntu", 22)]
|
||||
public void FindDerivativesFor_KnownCanonical_ReturnsDerivatives(string canonical, int release)
|
||||
{
|
||||
var derivatives = DistroMappings.FindDerivativesFor(canonical, release).ToList();
|
||||
|
||||
Assert.NotEmpty(derivatives);
|
||||
Assert.All(derivatives, d => Assert.Equal(canonical, d.CanonicalDistro));
|
||||
Assert.All(derivatives, d => Assert.Equal(release, d.MajorRelease));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindDerivativesFor_UnknownDistro_ReturnsEmpty()
|
||||
{
|
||||
var derivatives = DistroMappings.FindDerivativesFor("unknowndistro", 1).ToList();
|
||||
|
||||
Assert.Empty(derivatives);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindDerivativesFor_ResultsOrderedByConfidence()
|
||||
{
|
||||
var derivatives = DistroMappings.FindDerivativesFor("rhel", 9).ToList();
|
||||
|
||||
Assert.NotEmpty(derivatives);
|
||||
// All RHEL derivatives should be High confidence
|
||||
Assert.All(derivatives, d => Assert.Equal(DerivativeConfidence.High, d.Confidence));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("almalinux", 9, "rhel")]
|
||||
[InlineData("rocky", 9, "rhel")]
|
||||
[InlineData("centos", 7, "rhel")]
|
||||
[InlineData("oracle", 8, "rhel")]
|
||||
public void FindCanonicalFor_KnownDerivative_ReturnsCanonical(string derivative, int release, string expectedCanonical)
|
||||
{
|
||||
var canonical = DistroMappings.FindCanonicalFor(derivative, release);
|
||||
|
||||
Assert.NotNull(canonical);
|
||||
Assert.Equal(expectedCanonical, canonical.CanonicalDistro);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindCanonicalFor_UnknownDerivative_ReturnsNull()
|
||||
{
|
||||
var canonical = DistroMappings.FindCanonicalFor("unknowndistro", 1);
|
||||
|
||||
Assert.Null(canonical);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(DerivativeConfidence.High, 0.95)]
|
||||
[InlineData(DerivativeConfidence.Medium, 0.80)]
|
||||
public void GetConfidenceMultiplier_ReturnsExpectedValues(DerivativeConfidence confidence, decimal expected)
|
||||
{
|
||||
var multiplier = DistroMappings.GetConfidenceMultiplier(confidence);
|
||||
|
||||
Assert.Equal(expected, multiplier);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("rhel", true)]
|
||||
[InlineData("debian", true)]
|
||||
[InlineData("ubuntu", true)]
|
||||
[InlineData("sles", true)]
|
||||
[InlineData("alpine", true)]
|
||||
[InlineData("almalinux", false)]
|
||||
[InlineData("rocky", false)]
|
||||
[InlineData("linuxmint", false)]
|
||||
public void IsCanonicalDistro_ReturnsCorrectResult(string distro, bool expected)
|
||||
{
|
||||
var result = DistroMappings.IsCanonicalDistro(distro);
|
||||
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("redhat", "rhel")]
|
||||
[InlineData("red hat", "rhel")]
|
||||
[InlineData("red-hat", "rhel")]
|
||||
[InlineData("RHEL", "rhel")]
|
||||
[InlineData("alma", "almalinux")]
|
||||
[InlineData("almalinux-os", "almalinux")]
|
||||
[InlineData("rockylinux", "rocky")]
|
||||
[InlineData("rocky-linux", "rocky")]
|
||||
[InlineData("oracle linux", "oracle")]
|
||||
[InlineData("oraclelinux", "oracle")]
|
||||
[InlineData("opensuse", "opensuse-leap")]
|
||||
[InlineData("mint", "linuxmint")]
|
||||
[InlineData("popos", "pop")]
|
||||
[InlineData("pop_os", "pop")]
|
||||
[InlineData("debian", "debian")]
|
||||
[InlineData("ubuntu", "ubuntu")]
|
||||
public void NormalizeDistroName_ReturnsCanonicalForm(string input, string expected)
|
||||
{
|
||||
var result = DistroMappings.NormalizeDistroName(input);
|
||||
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindDerivativesFor_CaseInsensitive()
|
||||
{
|
||||
var lower = DistroMappings.FindDerivativesFor("rhel", 9).ToList();
|
||||
var upper = DistroMappings.FindDerivativesFor("RHEL", 9).ToList();
|
||||
var mixed = DistroMappings.FindDerivativesFor("RhEl", 9).ToList();
|
||||
|
||||
Assert.Equal(lower.Count, upper.Count);
|
||||
Assert.Equal(lower.Count, mixed.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindCanonicalFor_CaseInsensitive()
|
||||
{
|
||||
var lower = DistroMappings.FindCanonicalFor("almalinux", 9);
|
||||
var upper = DistroMappings.FindCanonicalFor("ALMALINUX", 9);
|
||||
var mixed = DistroMappings.FindCanonicalFor("AlmaLinux", 9);
|
||||
|
||||
Assert.NotNull(lower);
|
||||
Assert.NotNull(upper);
|
||||
Assert.NotNull(mixed);
|
||||
Assert.Equal(lower, upper);
|
||||
Assert.Equal(lower, mixed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<IsPackable>false</IsPackable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<UseXunitV3>true</UseXunitV3>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Moq" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\StellaOps.DistroIntel\StellaOps.DistroIntel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
|
||||
"diagnosticMessages": true,
|
||||
"parallelizeAssembly": true,
|
||||
"parallelizeTestCollections": true,
|
||||
"maxParallelThreads": -1
|
||||
}
|
||||
Reference in New Issue
Block a user