Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class VerificationEngine
/// <summary>
/// Signature of a Verify directory-verification entry point. This intentionally mirrors the
/// shape of <c>VerifyXunit.Verifier.VerifyDirectory</c> and <c>VerifyMSTest.Verifier.VerifyDirectory</c>
/// so that either can be assigned directly as a method group.
/// (including their <see cref="SettingsTask"/> return type) so that either can be assigned directly
/// as a method group.
/// </summary>
public delegate SettingsTask VerifyDirectoryDelegate(
string path,
Expand All @@ -48,12 +49,12 @@ public delegate SettingsTask VerifyDirectoryDelegate(
string sourceFile);

/// <summary>
/// Optional override for the test-framework-specific Verify directory verifier.
/// When unset, the built-in xUnit (v3) verifier is used. Consumers running under a different
/// test framework (for example MSTest) can set this to that framework's
/// <c>Verifier.VerifyDirectory</c> so snapshot verification resolves the ambient test context
/// of the active framework rather than xUnit's (which would otherwise be unavailable and fail
/// with <c>TestContext.TestMethod is null</c>).
/// Optional override for the test-framework-specific Verify directory verifier used by the
/// built-in (non-custom) verification path. When unset, the built-in xUnit (v3) verifier is used.
/// Consumers running under a different test framework (for example MSTest) can set this to that
/// framework's <c>Verifier.VerifyDirectory</c> so snapshot verification resolves the ambient test
/// context of the active framework rather than xUnit's (which would otherwise be unavailable and
/// fail with <c>TestContext.TestMethod is null</c>).
/// </summary>
public static VerifyDirectoryDelegate? DirectoryVerifier { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@

namespace Microsoft.NET.Build.Containers.IntegrationTests;

[TestClass]
public class ArchiveFileRegistryTests
{
[Fact]
[TestMethod]
public async Task ArchiveOutputPathIsExistingDirectory_CreatesFileWithRepositoryNameAndTarGz()
{
string archiveOutputPath = TestSettings.TestArtifactsDirectory;
string expectedCreatedFilePath = Path.Combine(TestSettings.TestArtifactsDirectory, "repository.tar.gz");

await CreateRegistryAndCallLoadAsync(archiveOutputPath);

Assert.True(File.Exists(expectedCreatedFilePath));
Assert.IsTrue(File.Exists(expectedCreatedFilePath));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
[TestMethod]
[DataRow(true)]
[DataRow(false)]
public async Task ArchiveOutputPathIsNonExistingDirectory_CreatesDirectoryAndFileWithRepositoryNameAndTarGz(bool includeDirectorySeperatorAtTheEnd)
{
string archiveOutputPath = Path.Combine(
Expand All @@ -30,29 +31,29 @@ public async Task ArchiveOutputPathIsNonExistingDirectory_CreatesDirectoryAndFil

await CreateRegistryAndCallLoadAsync(archiveOutputPath);

Assert.True(File.Exists(expectedCreatedFilePath));
Assert.IsTrue(File.Exists(expectedCreatedFilePath));
}

[Fact]
[TestMethod]
public async Task ArchiveOutputPathIsCustomFileNameInExistingDirectory_CreatesFileWithThatName()
{
string archiveOutputPath = Path.Combine(TestSettings.TestArtifactsDirectory, "custom-name.withextension");
string expectedCreatedFilePath = archiveOutputPath;

await CreateRegistryAndCallLoadAsync(archiveOutputPath);

Assert.True(File.Exists(expectedCreatedFilePath));
Assert.IsTrue(File.Exists(expectedCreatedFilePath));
}

[Fact]
[TestMethod]
public async Task ArchiveOutputPathIsCustomFileNameInNonExistingDirectory_CreatesDirectoryAndFileWithThatName()
{
string archiveOutputPath = Path.Combine(TestSettings.TestArtifactsDirectory, $"nonexisting-directory{Path.AltDirectorySeparatorChar}custom-name.withextension");
string expectedCreatedFilePath = archiveOutputPath;

await CreateRegistryAndCallLoadAsync(archiveOutputPath);

Assert.True(File.Exists(expectedCreatedFilePath));
Assert.IsTrue(File.Exists(expectedCreatedFilePath));
}

private async Task CreateRegistryAndCallLoadAsync(string archiveOutputPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@

namespace Microsoft.NET.Build.Containers.Tasks.IntegrationTests;

[Collection("Docker tests")]
public class CreateImageIndexTests
[TestClass]
[DoNotParallelize]
public class CreateImageIndexTests : SdkTest
{
private ITestOutputHelper _testOutput;

public CreateImageIndexTests(ITestOutputHelper testOutput)
{
_testOutput = testOutput;
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/49502")]
[TestMethod]
[Ignore("https://github.com/dotnet/sdk/issues/49502")]
public async Task CreateImageIndex_Baseline()
{
DirectoryInfo newProjectDir = CreateNewProject();
Expand All @@ -41,7 +36,7 @@ public async Task CreateImageIndex_Baseline()
cii.Repository = repository;
cii.ImageTags = tags;
cii.GeneratedContainers = [image1, image2];
Assert.True(cii.Execute(), FormatBuildMessages(errors));
Assert.IsTrue(cii.Execute(), FormatBuildMessages(errors));

// Assert that the image index is created correctly
cii.GeneratedImageIndex.Should().NotBeNullOrEmpty();
Expand All @@ -57,7 +52,7 @@ public async Task CreateImageIndex_Baseline()
imageIndex.manifests[1].platform.architecture.Should().Be("arm64");

// Assert that the image index is pushed to the registry
var loggerFactory = new TestLoggerFactory(_testOutput);
var loggerFactory = new TestLoggerFactory(Log);
var logger = loggerFactory.CreateLogger(nameof(CreateImageIndex_Baseline));
Registry registry = new(outputRegistry, logger, RegistryMode.Pull);

Expand All @@ -75,7 +70,7 @@ private DirectoryInfo CreateNewProject()
newProjectDir.Delete(recursive: true);
}
newProjectDir.Create();
new DotnetNewCommand(_testOutput, "console", "-f", ToolsetInfo.CurrentTargetFramework)
new DotnetNewCommand(Log, "console", "-f", ToolsetInfo.CurrentTargetFramework)
.WithVirtualHive()
.WithWorkingDirectory(newProjectDir.FullName)
.Execute()
Expand All @@ -92,7 +87,7 @@ private TaskItem PublishAndCreateNewImage(
IBuildEngine buildEngine,
List<string?> errors)
{
new DotnetCommand(_testOutput, "publish", "-c", "Release", "-r", rid, "--no-self-contained")
new DotnetCommand(Log, "publish", "-c", "Release", "-r", rid, "--no-self-contained")
.WithWorkingDirectory(newProjectDir.FullName)
.Execute()
.Should().Pass();
Expand All @@ -106,7 +101,7 @@ private TaskItem PublishAndCreateNewImage(
cni.BaseImageTag = "7.0";

cni.OutputRegistry = outputRegistry;
cni.LocalRegistry = DockerAvailableFactAttribute.LocalRegistry;
cni.LocalRegistry = DockerUnavailableCondition.LocalRegistry;
cni.PublishDirectory = Path.Combine(newProjectDir.FullName, "bin", "Release", ToolsetInfo.CurrentTargetFramework, rid, "publish");
cni.Repository = repository;
cni.ImageTags = tags.Select(t => $"{t}-{rid}").ToArray();
Expand All @@ -115,7 +110,7 @@ private TaskItem PublishAndCreateNewImage(
cni.Entrypoint = new TaskItem[] { new("dotnet"), new("build") };
cni.RuntimeIdentifierGraphPath = ToolsetUtils.GetRuntimeGraphFilePath();

Assert.True(cni.Execute(), FormatBuildMessages(errors));
Assert.IsTrue(cni.Execute(), FormatBuildMessages(errors));

TaskItem generatedContainer = new("GeneratedContainer" + rid);
generatedContainer.SetMetadata("Manifest", cni.GeneratedContainerManifest);
Expand Down
Loading
Loading