Skip to content

Commit 4a00c93

Browse files
authored
Add snapshot tests for internal Dockerfiles using Shouldly (#6191)
1 parent e86047e commit 4a00c93

487 files changed

Lines changed: 18700 additions & 48 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complem
7878
src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/knucleotide-input.txt text eol=lf
7979
src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/knucleotide-input-big.txt text eol=lf
8080
src/coreclr/tests/src/performance/Scenario/JitBench/Resources/word2vecnet.patch text eol=lf
81+
82+
tests/Microsoft.DotNet.Docker.Tests/Baselines/** linguist-generated

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ artifacts/
2626

2727
# ImageBuilder directory
2828
.Microsoft.DotNet.ImageBuilder
29+
30+
# Snapshots for acceptance testing (Shouldly)
31+
*.received.*

CONTRIBUTING.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ The [READMEs](https://github.com/search?q=repo%3Adotnet%2Fdotnet-docker+path%3A*
8383

8484
### Tests
8585

86-
There are two basic types of [tests](https://github.com/dotnet/dotnet-docker/tree/main/tests) for each of the images produced from this repo.
86+
There are several types of [tests](https://github.com/dotnet/dotnet-docker/tree/main/tests) in this repo.
8787

88-
1. Unit tests that validate the static state of images. This includes things like verifing which environment variables are defined.
89-
1. Scenario tests that validate basic usage scenarios. For example the SDK image is used to create, build and run a new console app.
88+
1. Image tests
89+
- Unit tests that validate the static state of images, based on their filesystem contents or manifest/image config.
90+
This includes things like verifying which environment variables are defined and which packages are installed.
91+
- Scenario tests that run images to validate basic user scenarios.
92+
For example, use the SDK image to create, build and run a .NET app.
93+
1. `"pre-build"` tests
94+
- Validate that tags adhere to a specific set of rules ([`StaticTagTests.cs`](tests/Microsoft.DotNet.Docker.Tests/StaticTagTests.cs))
95+
- Verify the state of generated Dockerfile templates (public and internal versions)
9096

9197
When editing Dockerfiles, please ensure the appropriate test changes are also made.
9298

@@ -113,7 +119,18 @@ From the "Run and Debug" sidebar panel, run the "Attach .NET Debugger" launch co
113119
VS Code will prompt you for a process ID to attach to.
114120
Type in the PID that was printed to the terminal earlier.
115121
Now, VS Code is attached to the .NET Debugger.
116-
You can press F5 (Continue) to start test execution.
122+
Press F5 (Continue) to start test execution.
123+
124+
#### Verifying Internal Dockerfiles
125+
126+
Internal Dockerfiles are validated using "snapshot" testing, which uses tooling to record and test the accepted state of the Dockerfiles.
127+
If your changes fail tests due to changes in the internal Dockerfiles, you will need to review the changes before the tests can pass.
128+
You can use a local dotnet tool to accept or reject the changes.
129+
130+
1. Run the failing test(s). For example: `./tests/run-tests.ps1 -Paths "*" -TestCategories "pre-build" -CustomTestFilter "VerifyInternalDockerfilesOutput"`
131+
1. The failing test will output updated baseline files in the `tests/Microsoft.DotNet.Docker.Tests/Baselines/` directory, ending in `*.received.txt`.
132+
1. Accept or discard the changes: `./tests/accept-changes.ps1 [-Discard]`. This script will either rename all of the `.received.txt` files to `.approved.txt` or remove them.
133+
1. If the git diff of the changes look acceptable, then commit the changes.
117134

118135
### Metadata Changes
119136

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
#!/usr/bin/env pwsh
22
param(
33
[switch]$Validate,
4-
[string]$Branch
4+
[string]$Branch,
5+
[string]$OutputDirectory,
6+
[string]$CustomImageBuilderArgs
57
)
68

79
Import-Module -force $PSScriptRoot/../DependencyManagement.psm1
810

11+
if (-Not $CustomImageBuilderArgs) {
12+
$CustomImageBuilderArgs = ""
13+
}
14+
915
if ($Validate) {
10-
$customImageBuilderArgs = " --validate"
16+
$CustomImageBuilderArgs += " --validate"
1117
}
1218

13-
$repoRoot = (Get-Item "$PSScriptRoot").Parent.Parent.FullName
19+
if (-Not $OutputDirectory) {
20+
$repoRoot = (Get-Item "$PSScriptRoot").Parent.Parent.FullName
21+
$OutputDirectory = $repoRoot
22+
}
1423

1524
$onDockerfilesGenerated = {
1625
param($ContainerName)
1726

1827
if (-Not $Validate) {
19-
Exec "docker cp ${ContainerName}:/repo/src $repoRoot"
28+
Exec "docker cp ${ContainerName}:/repo/src $OutputDirectory"
2029
}
2130
}
2231

@@ -25,5 +34,5 @@ if (!$Branch) {
2534
}
2635

2736
& $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 `
28-
-ImageBuilderArgs "generateDockerfiles $customImageBuilderArgs --var branch=$Branch" `
37+
-ImageBuilderArgs "generateDockerfiles $CustomImageBuilderArgs --var branch=$Branch" `
2938
-OnCommandExecuted $onDockerfilesGenerated

tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/aspire-dashboard-9.0-cbl-mariner-distroless-amd64-Dockerfile.approved.txt

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/aspire-dashboard-9.0-cbl-mariner-distroless-arm64v8-Dockerfile.approved.txt

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/aspnet-10.0-alpine3.21-amd64-Dockerfile.approved.txt

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/aspnet-10.0-alpine3.21-arm32v7-Dockerfile.approved.txt

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/aspnet-10.0-alpine3.21-arm64v8-Dockerfile.approved.txt

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/aspnet-10.0-alpine3.21-composite-amd64-Dockerfile.approved.txt

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)