Skip to content

Commit a0384b8

Browse files
Copilotjongalloway
andcommitted
Add tests and verification script for Docker build fix
Co-authored-by: jongalloway <[email protected]>
1 parent bd18aec commit a0384b8

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

test-docker-fix.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Test script to verify Docker build functionality for NLWebNet Demo
4+
# This script verifies that the Docker build can successfully copy all project files
5+
6+
set -e
7+
8+
echo "Testing Docker build file copying stage..."
9+
10+
# Build only up to the file copying stage to verify all referenced files exist
11+
docker build -f deployment/docker/Dockerfile --target build --no-cache -t nlwebnet-build-test . 2>&1 | head -20
12+
13+
echo ""
14+
echo "Docker build file copying stage test completed successfully!"
15+
echo "All project files referenced in the Dockerfile exist and can be copied."
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System.IO;
3+
using System.Text.RegularExpressions;
4+
5+
namespace NLWebNet.Tests.Docker;
6+
7+
[TestClass]
8+
public class DockerfileTests
9+
{
10+
[TestMethod]
11+
public void Dockerfile_AllReferencedProjectFilesExist()
12+
{
13+
// Arrange
14+
var rootPath = GetRepositoryRoot();
15+
var dockerfilePath = Path.Combine(rootPath, "deployment/docker/Dockerfile");
16+
17+
Assert.IsTrue(File.Exists(dockerfilePath), $"Dockerfile not found at {dockerfilePath}");
18+
19+
var dockerfileContent = File.ReadAllText(dockerfilePath);
20+
21+
// Extract COPY commands that reference .csproj files
22+
var copyPattern = @"COPY \[""([^""]+\.csproj)"", ""[^""]+/""\]";
23+
var matches = Regex.Matches(dockerfileContent, copyPattern);
24+
25+
// Act & Assert
26+
foreach (Match match in matches)
27+
{
28+
var projectPath = match.Groups[1].Value;
29+
var fullPath = Path.Combine(rootPath, projectPath);
30+
31+
Assert.IsTrue(File.Exists(fullPath),
32+
$"Project file referenced in Dockerfile does not exist: {projectPath} (Full path: {fullPath})");
33+
}
34+
35+
// Verify we found at least the expected project files
36+
Assert.IsTrue(matches.Count >= 3,
37+
"Expected to find at least 3 project file references in Dockerfile (NLWebNet, Demo, Tests)");
38+
}
39+
40+
[TestMethod]
41+
public void Dockerfile_DoesNotReferenceAspireHostProject()
42+
{
43+
// Arrange
44+
var rootPath = GetRepositoryRoot();
45+
var dockerfilePath = Path.Combine(rootPath, "deployment/docker/Dockerfile");
46+
47+
Assert.IsTrue(File.Exists(dockerfilePath), $"Dockerfile not found at {dockerfilePath}");
48+
49+
var dockerfileContent = File.ReadAllText(dockerfilePath);
50+
51+
// Act & Assert
52+
Assert.IsFalse(dockerfileContent.Contains("AspireHost"),
53+
"Dockerfile should not contain references to AspireHost project");
54+
Assert.IsFalse(dockerfileContent.Contains("NLWebNet.AspireHost.csproj"),
55+
"Dockerfile should not contain references to NLWebNet.AspireHost.csproj");
56+
}
57+
58+
private static string GetRepositoryRoot()
59+
{
60+
var currentDirectory = Directory.GetCurrentDirectory();
61+
var directory = new DirectoryInfo(currentDirectory);
62+
63+
while (directory != null && !File.Exists(Path.Combine(directory.FullName, "NLWebNet.sln")))
64+
{
65+
directory = directory.Parent;
66+
}
67+
68+
Assert.IsNotNull(directory, "Could not find repository root (NLWebNet.sln not found)");
69+
return directory.FullName;
70+
}
71+
}

0 commit comments

Comments
 (0)