61 lines
2.4 KiB
C#
61 lines
2.4 KiB
C#
using System.Text.Json;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
|
|
using StellaOps.TestKit;
|
|
namespace StellaOps.Reachability.FixtureTests;
|
|
|
|
public sealed class FixtureCoverageTests
|
|
{
|
|
private static readonly string RepoRoot = ReachbenchFixtureTests.LocateRepoRoot();
|
|
private static readonly string ReachabilityRoot = Path.Combine(RepoRoot, "tests", "reachability");
|
|
private static readonly string CorpusRoot = Path.Combine(ReachabilityRoot, "corpus");
|
|
private static readonly string SamplesPublicRoot = Path.Combine(ReachabilityRoot, "samples-public");
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void CorpusAndPublicSamplesCoverExpectedLanguageBuckets()
|
|
{
|
|
var corpusLanguages = ReadManifestLanguages(Path.Combine(CorpusRoot, "manifest.json"));
|
|
corpusLanguages.Should().Contain(new[] { "dotnet", "go", "python", "rust" });
|
|
|
|
var samplesLanguages = ReadManifestLanguages(Path.Combine(SamplesPublicRoot, "manifest.json"));
|
|
samplesLanguages.Should().Contain(new[] { "csharp", "js", "php" });
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void CorpusManifestIsSorted()
|
|
{
|
|
var keys = ReadManifestKeys(Path.Combine(CorpusRoot, "manifest.json"));
|
|
keys.Should().NotBeEmpty("corpus manifest should have entries");
|
|
keys.Should().BeInAscendingOrder(StringComparer.Ordinal);
|
|
}
|
|
|
|
private static string[] ReadManifestLanguages(string manifestPath)
|
|
{
|
|
File.Exists(manifestPath).Should().BeTrue($"{manifestPath} should exist");
|
|
|
|
using var doc = JsonDocument.Parse(File.ReadAllBytes(manifestPath));
|
|
return doc.RootElement.EnumerateArray()
|
|
.Select(entry => entry.GetProperty("language").GetString())
|
|
.Where(language => !string.IsNullOrWhiteSpace(language))
|
|
.Select(language => language!)
|
|
.Distinct(StringComparer.Ordinal)
|
|
.OrderBy(language => language, StringComparer.Ordinal)
|
|
.ToArray();
|
|
}
|
|
|
|
private static string[] ReadManifestKeys(string manifestPath)
|
|
{
|
|
File.Exists(manifestPath).Should().BeTrue($"{manifestPath} should exist");
|
|
|
|
using var doc = JsonDocument.Parse(File.ReadAllBytes(manifestPath));
|
|
return doc.RootElement.EnumerateArray()
|
|
.Select(entry => $"{entry.GetProperty("language").GetString()}/{entry.GetProperty("id").GetString()}")
|
|
.ToArray();
|
|
}
|
|
}
|
|
|