Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snapshot tests for internal Dockerfiles #6142

Open
wants to merge 5 commits into
base: nightly
Choose a base branch
from

Conversation

lbussell
Copy link
Contributor

@lbussell lbussell commented Jan 9, 2025

Fixes #5935

Uses https://github.com/VerifyTests/Verify to implement snapshot testing for internal Dockerfiles.

Internal Dockerfiles are scrubbed of versions and shas, and then checked-in to tests/Microsoft.DotNet.Docker.Tests/Baselines/. When tests are ran, internal Dockerfiles will be generated and compared to the checked-in versions. If there is a diff, you'll have the opportunity to review and accept differences.

The easiest way to accept or reject new changes is using Verify.Terminal in the repo root:

dotnet tool restore
dotnet tool run verify review

Todo:

  • CONTRIBUTING documentation for using the review tool
  • Upload new baselines as pipeline artifact when tests fail

@@ -10,7 +10,7 @@
set isFullAzureLinux to isAzureLinux && !isDistroless ^
set isDistrolessAzureLinux to isAzureLinux && isDistroless ^
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
set isInternal to VARIABLES["IsInternal"] || find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I'd like to avoid having to depend on an IsInternal variable to keep things simple. Is it possible for the Get-GeneratedDockerfiles script to override the URL instead so that it matches with artifacts.visualstudio.com? Or for the test to update the content of the manifest.versions.json file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the first thing that I tried. I ran into lots and lots of issues getting the right combination of escape characters to pass arguments through with the correct --var variable="foo" syntax. It ended up wasting lots of time. I added the new override variable just to get things working. I can give this one more try though.

[GeneratedRegex(@"alpine\d+\.\d+")]
private static partial Regex AlpineVersionRegex { get; }

private static List<(Regex pattern, string replacement)> Patterns { get; } =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static List<(Regex pattern, string replacement)> Patterns { get; } =
private static List<(Regex pattern, string replacement)> PatternReplacements { get; } =

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments to this file explaining what it's all about? It's not clear to me.

@lbussell
Copy link
Contributor Author

Not sure why there is a diff with the generated internal dockerfiles here. I can't reproduce the test failure locally. The CI output should ideally show the text diff as well, which would make this easier to diagnose. I think the issue there is that the library doesn't think that Dockerfiles are text files (because they have no file extension), so it doesn't try to show the diff. I'll look into it more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants