1
+ // Licensed to the .NET Foundation under one or more agreements.
2
+ // The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+ using Microsoft . NET . Build . Containers . LocalDaemons ;
5
+
6
+ namespace Microsoft . NET . Build . Containers . IntegrationTests ;
7
+
8
+ public class ArchiveFileRegistryTests
9
+ {
10
+ [ Fact ]
11
+ public async Task ArchiveOutputPathIsExistingDirectory_CreatesFileWithRepositoryNameAndTarGz ( )
12
+ {
13
+ string archiveOutputPath = TestSettings . TestArtifactsDirectory ;
14
+ string expectedCreatedFilePath = Path . Combine ( TestSettings . TestArtifactsDirectory , "repository.tar.gz" ) ;
15
+
16
+ await CreateRegistryAndCallLoadAsync ( archiveOutputPath ) . ConfigureAwait ( false ) ;
17
+
18
+ Assert . True ( File . Exists ( expectedCreatedFilePath ) ) ;
19
+ }
20
+
21
+ [ Theory ]
22
+ [ InlineData ( true ) ]
23
+ [ InlineData ( false ) ]
24
+ public async Task ArchiveOutputPathIsNonExistingDirectory_CreatesDirectoryAndFileWithRepositoryNameAndTarGz ( bool includeDirectorySeperatorAtTheEnd )
25
+ {
26
+ string archiveOutputPath = Path . Combine (
27
+ TestSettings . TestArtifactsDirectory ,
28
+ "nonexisting" + ( includeDirectorySeperatorAtTheEnd ? Path . DirectorySeparatorChar : "" ) ) ;
29
+ string expectedCreatedFilePath = Path . Combine ( archiveOutputPath , "repository.tar.gz" ) ;
30
+
31
+ await CreateRegistryAndCallLoadAsync ( archiveOutputPath ) . ConfigureAwait ( false ) ;
32
+
33
+ Assert . True ( File . Exists ( expectedCreatedFilePath ) ) ;
34
+ }
35
+
36
+ [ Fact ]
37
+ public async Task ArchiveOutputPathIsCustomFileNameInExistingDirectory_CreatesFileWithThatName ( )
38
+ {
39
+ string archiveOutputPath = Path . Combine ( TestSettings . TestArtifactsDirectory , "custom-name.withextension" ) ;
40
+ string expectedCreatedFilePath = archiveOutputPath ;
41
+
42
+ await CreateRegistryAndCallLoadAsync ( archiveOutputPath ) . ConfigureAwait ( false ) ;
43
+
44
+ Assert . True ( File . Exists ( expectedCreatedFilePath ) ) ;
45
+ }
46
+
47
+ [ Fact ]
48
+ public async Task ArchiveOutputPathIsCustomFileNameInNonExistingDirectory_CreatesDirectoryAndFileWithThatName ( )
49
+ {
50
+ string archiveOutputPath = Path . Combine ( TestSettings . TestArtifactsDirectory , $ "nonexisting-directory{ Path . AltDirectorySeparatorChar } custom-name.withextension") ;
51
+ string expectedCreatedFilePath = archiveOutputPath ;
52
+
53
+ await CreateRegistryAndCallLoadAsync ( archiveOutputPath ) . ConfigureAwait ( false ) ;
54
+
55
+ Assert . True ( File . Exists ( expectedCreatedFilePath ) ) ;
56
+ }
57
+
58
+ private async Task CreateRegistryAndCallLoadAsync ( string archiveOutputPath )
59
+ {
60
+ var registry = new ArchiveFileRegistry ( archiveOutputPath ) ;
61
+ var destinationImageReference = new DestinationImageReference ( registry , "repository" , [ "tag" ] ) ;
62
+
63
+ await registry . LoadAsync (
64
+ "test image" ,
65
+ new SourceImageReference ( ) ,
66
+ destinationImageReference ,
67
+ CancellationToken . None ,
68
+ async ( img , srcRef , destRef , stream , token ) =>
69
+ {
70
+ await Task . CompletedTask ;
71
+ } ) . ConfigureAwait ( false ) ;
72
+ }
73
+ }
0 commit comments