Skip to content

Commit

Permalink
chore: Add test to ensure that all test projects are configured for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced authored Nov 24, 2024
1 parent 37e5351 commit 6051cdb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/Testcontainers.Tests/ContinuousIntegration/JobsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace DotNet.Testcontainers.Tests.ContinuousIntegration
{
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Xunit;

public partial class JobsTest
{
[GeneratedRegex("name: \"(.+?)\"")]
private static partial Regex ProjectNameRegex();

[Fact]
public void AllTestProjectsShouldBeConfiguredForContinuousIntegration()
{
var ciCdFilePath = GetCiCdFilePath();
var configuredProjects = File.ReadAllLines(ciCdFilePath).Select(line => ProjectNameRegex().Match(line).Groups[1].Value).Where(line => line.Length > 0).ToList();
Assert.NotEmpty(configuredProjects);

var existingProjects = Directory.GetFiles(GetTestsPath(), "*.Tests.csproj", SearchOption.AllDirectories).Select(name => Path.GetFileName(name)[..^13]).ToList();
Assert.NotEmpty(existingProjects);

var missingConfiguredProjects = existingProjects.Except(configuredProjects).ToList();
if (missingConfiguredProjects.Count > 0)
{
Assert.Fail($"{string.Join(", ", missingConfiguredProjects)} must be configured in {ciCdFilePath}");
}
}

private static string GetCiCdFilePath() => Path.Combine(GetRepositoryPath(), ".github", "workflows", "cicd.yml");

private static string GetTestsPath() => Path.Combine(GetRepositoryPath(), "tests");

private static string GetRepositoryPath([CallerFilePath] string path = "") => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path)!, "..", "..", ".."));
}
}

0 comments on commit 6051cdb

Please sign in to comment.