@@ -33,8 +33,18 @@ public void TestFileExistsInTarFile()
33
33
}
34
34
35
35
[ UsedImplicitly ]
36
- public sealed class FromResourceMapping : TarOutputMemoryStreamTest , IResourceMapping , IAsyncLifetime , IDisposable
36
+ public sealed class FromResourceMapping : TarOutputMemoryStreamTest , IResourceMapping , IClassFixture < FromResourceMapping . HttpFixture > , IAsyncLifetime , IDisposable
37
37
{
38
+ private readonly string _testHttpUri ;
39
+
40
+ private readonly string _testFileUri ;
41
+
42
+ public FromResourceMapping ( FromResourceMapping . HttpFixture httpFixture )
43
+ {
44
+ _testHttpUri = httpFixture . BaseAddress ;
45
+ _testFileUri = new Uri ( _testFile . FullName ) . ToString ( ) ;
46
+ }
47
+
38
48
public MountType Type
39
49
=> MountType . Bind ;
40
50
@@ -86,31 +96,32 @@ public async Task TestFileExistsInContainer()
86
96
{
87
97
// Given
88
98
var targetFilePath1 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) , _testFile . Name ) ;
89
-
90
99
var targetFilePath2 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) , _testFile . Name ) ;
91
-
100
+ var targetFilePath3 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) , _testFile . Name ) ;
92
101
var targetDirectoryPath1 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) ) ;
93
-
94
102
var targetDirectoryPath2 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) ) ;
95
-
96
103
var targetDirectoryPath3 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) ) ;
97
-
98
104
var targetDirectoryPath4 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) ) ;
105
+ var targetDirectoryPath5 = string . Join ( "/" , string . Empty , "tmp" , Guid . NewGuid ( ) ) ;
99
106
100
107
var targetFilePaths = new List < string > ( ) ;
101
108
targetFilePaths . Add ( targetFilePath1 ) ;
102
109
targetFilePaths . Add ( targetFilePath2 ) ;
110
+ targetFilePaths . Add ( targetFilePath3 ) ;
103
111
targetFilePaths . Add ( string . Join ( "/" , targetDirectoryPath1 , _testFile . Name ) ) ;
104
112
targetFilePaths . Add ( string . Join ( "/" , targetDirectoryPath2 , _testFile . Name ) ) ;
105
113
targetFilePaths . Add ( string . Join ( "/" , targetDirectoryPath3 , _testFile . Name ) ) ;
106
114
targetFilePaths . Add ( string . Join ( "/" , targetDirectoryPath4 , _testFile . Name ) ) ;
115
+ targetFilePaths . Add ( string . Join ( "/" , targetDirectoryPath5 , _testFile . Name ) ) ;
107
116
108
117
await using var container = new ContainerBuilder ( )
109
118
. WithImage ( CommonImages . Alpine )
110
119
. WithEntrypoint ( CommonCommands . SleepInfinity )
111
120
. WithResourceMapping ( _testFile , new FileInfo ( targetFilePath1 ) )
112
121
. WithResourceMapping ( _testFile . FullName , targetDirectoryPath1 )
113
122
. WithResourceMapping ( _testFile . Directory . FullName , targetDirectoryPath2 )
123
+ . WithResourceMapping ( _testHttpUri , targetFilePath2 )
124
+ . WithResourceMapping ( _testFileUri , targetDirectoryPath3 )
114
125
. Build ( ) ;
115
126
116
127
// When
@@ -120,13 +131,13 @@ public async Task TestFileExistsInContainer()
120
131
await container . StartAsync ( )
121
132
. ConfigureAwait ( true ) ;
122
133
123
- await container . CopyAsync ( fileContent , targetFilePath2 )
134
+ await container . CopyAsync ( fileContent , targetFilePath3 )
124
135
. ConfigureAwait ( true ) ;
125
136
126
- await container . CopyAsync ( _testFile . FullName , targetDirectoryPath3 )
137
+ await container . CopyAsync ( _testFile . FullName , targetDirectoryPath4 )
127
138
. ConfigureAwait ( true ) ;
128
139
129
- await container . CopyAsync ( _testFile . Directory . FullName , targetDirectoryPath4 )
140
+ await container . CopyAsync ( _testFile . Directory . FullName , targetDirectoryPath5 )
130
141
. ConfigureAwait ( true ) ;
131
142
132
143
// Then
@@ -135,6 +146,31 @@ await container.CopyAsync(_testFile.Directory.FullName, targetDirectoryPath4)
135
146
136
147
Assert . All ( execResults , result => Assert . Equal ( 0 , result . ExitCode ) ) ;
137
148
}
149
+
150
+ public sealed class HttpFixture : IAsyncLifetime
151
+ {
152
+ private const ushort HttpPort = 80 ;
153
+
154
+ private readonly IContainer _container = new ContainerBuilder ( )
155
+ . WithImage ( CommonImages . Alpine )
156
+ . WithEntrypoint ( "/bin/sh" , "-c" )
157
+ . WithCommand ( $ "while true; do echo \" HTTP/1.1 200 OK\r \n \" | nc -l -p { HttpPort } ; done")
158
+ . WithPortBinding ( HttpPort , true )
159
+ . Build ( ) ;
160
+
161
+ public string BaseAddress
162
+ => new UriBuilder ( Uri . UriSchemeHttp , _container . Hostname , _container . GetMappedPublicPort ( HttpPort ) ) . ToString ( ) ;
163
+
164
+ public Task InitializeAsync ( )
165
+ {
166
+ return _container . StartAsync ( ) ;
167
+ }
168
+
169
+ public Task DisposeAsync ( )
170
+ {
171
+ return _container . DisposeAsync ( ) . AsTask ( ) ;
172
+ }
173
+ }
138
174
}
139
175
140
176
[ UsedImplicitly ]
0 commit comments