-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add test to ensure that all test projects are configured for CI
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
tests/Testcontainers.Tests/ContinuousIntegration/JobsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)!, "..", "..", "..")); | ||
} | ||
} |