Skip to content

Commit ee3029b

Browse files
committed
fix test
1 parent aa67ae3 commit ee3029b

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -130,35 +130,7 @@ public async Task ApiEndToEndWithLocalLoad()
130130
[DockerAvailableFact]
131131
public async Task ApiEndToEndWithArchiveWritingAndLoad()
132132
{
133-
var archiveFile = Path.Combine(TestSettings.TestArtifactsDirectory,
134-
nameof(ApiEndToEndWithArchiveWritingAndLoad), "app.tar.gz");
135-
136-
// Build the image
137-
(BuiltImage builtImage, SourceImageReference sourceReference, DestinationImageReference destinationReference) =
138-
await BuildDockerImageWithArciveDestinationAsync(archiveFile, ["latest", "1.0"], nameof(ApiEndToEndWithArchiveWritingAndLoad));
139-
140-
// Write the image to disk
141-
await destinationReference.LocalRegistry!.LoadAsync(builtImage, sourceReference, destinationReference, default).ConfigureAwait(false);
142-
143-
Assert.True(File.Exists(archiveFile), $"File.Exists({archiveFile})");
144-
145-
// Load the archive
146-
ContainerCli.LoadCommand(_testOutput, "--input", archiveFile)
147-
.Execute()
148-
.Should().Pass();
149-
150-
// Run the image
151-
foreach (string tag in destinationReference.Tags)
152-
{
153-
ContainerCli.RunCommand(_testOutput, "--rm", "--tty", $"{NewImageName()}:{tag}")
154-
.Execute()
155-
.Should().Pass();
156-
}
157-
}
158-
159-
private async Task<(BuiltImage image, SourceImageReference sourceReference, DestinationImageReference destinationReference)> BuildDockerImageWithArciveDestinationAsync(string archiveFile, string[] tags, string testName)
160-
{
161-
ILogger logger = _loggerFactory.CreateLogger(testName);
133+
ILogger logger = _loggerFactory.CreateLogger(nameof(ApiEndToEndWithArchiveWritingAndLoad));
162134
string publishDirectory = BuildLocalApp(tfm: "net8.0");
163135

164136
// Build the image
@@ -182,10 +154,27 @@ public async Task ApiEndToEndWithArchiveWritingAndLoad()
182154
BuiltImage builtImage = imageBuilder.Build();
183155

184156
// Write the image to disk
157+
var archiveFile = Path.Combine(TestSettings.TestArtifactsDirectory,
158+
nameof(ApiEndToEndWithArchiveWritingAndLoad), "app.tar.gz");
185159
var sourceReference = new SourceImageReference(registry, DockerRegistryManager.RuntimeBaseImage, DockerRegistryManager.Net7ImageTag);
186-
var destinationReference = new DestinationImageReference(new ArchiveFileRegistry(archiveFile), NewImageName(), tags);
160+
var destinationReference = new DestinationImageReference(new ArchiveFileRegistry(archiveFile), NewImageName(), new[] { "latest", "1.0" });
187161

188-
return (builtImage, sourceReference, destinationReference);
162+
await destinationReference.LocalRegistry!.LoadAsync(builtImage, sourceReference, destinationReference, default).ConfigureAwait(false);
163+
164+
Assert.True(File.Exists(archiveFile), $"File.Exists({archiveFile})");
165+
166+
// Load the archive
167+
ContainerCli.LoadCommand(_testOutput, "--input", archiveFile)
168+
.Execute()
169+
.Should().Pass();
170+
171+
// Run the image
172+
foreach (string tag in destinationReference.Tags)
173+
{
174+
ContainerCli.RunCommand(_testOutput, "--rm", "--tty", $"{NewImageName()}:{tag}")
175+
.Execute()
176+
.Should().Pass();
177+
}
189178
}
190179

191180
[DockerAvailableFact]
@@ -214,6 +203,28 @@ public async Task TarballsHaveCorrectStructure()
214203
CheckOciTarballStructure(archiveFile);
215204
}
216205

206+
private async Task<(BuiltImage image, SourceImageReference sourceReference, DestinationImageReference destinationReference)> BuildDockerImageWithArciveDestinationAsync(string archiveFile, string[] tags, string testName)
207+
{
208+
ILogger logger = _loggerFactory.CreateLogger(testName);
209+
Registry registry = new(DockerRegistryManager.LocalRegistry, logger, RegistryMode.Push);
210+
211+
ImageBuilder imageBuilder = await registry.GetImageManifestAsync(
212+
DockerRegistryManager.RuntimeBaseImage,
213+
DockerRegistryManager.Net8ImageTag,
214+
"linux-x64",
215+
ToolsetUtils.RidGraphManifestPicker,
216+
cancellationToken: default).ConfigureAwait(false);
217+
Assert.NotNull(imageBuilder);
218+
219+
BuiltImage builtImage = imageBuilder.Build();
220+
221+
// Write the image to disk
222+
var sourceReference = new SourceImageReference(registry, DockerRegistryManager.RuntimeBaseImage, DockerRegistryManager.Net7ImageTag);
223+
var destinationReference = new DestinationImageReference(new ArchiveFileRegistry(archiveFile), NewImageName(), tags);
224+
225+
return (builtImage, sourceReference, destinationReference);
226+
}
227+
217228
private BuiltImage ConvertToOciImage(BuiltImage builtImage)
218229
{
219230
// Convert the image to an OCI image

0 commit comments

Comments
 (0)