Skip to content

Commit fe974c9

Browse files
committed
Add a new test that ensure that all test projects are configured for CI
Because it's too easy to forget to add a line in the cicd.yml after creating a new module. This is a safety measure after the introduction of running each test project on a separate runner in #1295.
1 parent 37e5351 commit fe974c9

File tree

1 file changed

+37
-0
lines changed
  • tests/Testcontainers.Tests/ContinuousIntegration

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace DotNet.Testcontainers.Tests.ContinuousIntegration
2+
{
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Text.RegularExpressions;
7+
using Xunit;
8+
9+
public partial class JobsTest
10+
{
11+
[GeneratedRegex("name: \"(.+?)\"")]
12+
private static partial Regex ProjectNameRegex();
13+
14+
[Fact]
15+
public void AllTestProjectsShouldBeConfiguredForContinuousIntegration()
16+
{
17+
var ciCdFilePath = GetCiCdFilePath();
18+
var configuredProjects = File.ReadAllLines(ciCdFilePath).Select(line => ProjectNameRegex().Match(line).Groups[1].Value).Where(line => line.Length > 0).ToList();
19+
Assert.NotEmpty(configuredProjects);
20+
21+
var existingProjects = Directory.GetFiles(GetTestsPath(), "*.Tests.csproj", SearchOption.AllDirectories).Select(name => Path.GetFileName(name)[..^13]).ToList();
22+
Assert.NotEmpty(existingProjects);
23+
24+
var missingConfiguredProjects = existingProjects.Except(configuredProjects).ToList();
25+
if (missingConfiguredProjects.Count > 0)
26+
{
27+
Assert.Fail($"{string.Join(", ", missingConfiguredProjects)} must be configured in {ciCdFilePath}");
28+
}
29+
}
30+
31+
private static string GetCiCdFilePath() => Path.Combine(GetRepositoryPath(), ".github", "workflows", "cicd.yml");
32+
33+
private static string GetTestsPath() => Path.Combine(GetRepositoryPath(), "tests");
34+
35+
private static string GetRepositoryPath([CallerFilePath] string path = "") => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path)!, "..", "..", ".."));
36+
}
37+
}

0 commit comments

Comments
 (0)