1
1
namespace DotNet . Testcontainers . Tests . Unit
2
2
{
3
3
using System ;
4
+ using System . Collections . Generic ;
5
+ using System . IO ;
4
6
using System . Threading . Tasks ;
5
7
using Azure ;
6
8
using Azure . Data . Tables ;
@@ -14,7 +16,11 @@ namespace DotNet.Testcontainers.Tests.Unit
14
16
[ Collection ( nameof ( Testcontainers ) ) ]
15
17
public sealed class AzuriteTestcontainerTest : IAsyncLifetime
16
18
{
19
+ // We cannot use `Path.GetTempPath()` on macOS, see: https://github.com/common-workflow-language/cwltool/issues/328.
20
+ private static readonly string TempDir = Environment . GetEnvironmentVariable ( "AGENT_TEMPDIRECTORY" ) ?? Directory . GetCurrentDirectory ( ) ;
21
+
17
22
private AzuriteTestcontainer container ;
23
+ private string testDir ;
18
24
19
25
public Task InitializeAsync ( )
20
26
{
@@ -23,6 +29,12 @@ public Task InitializeAsync()
23
29
24
30
public Task DisposeAsync ( )
25
31
{
32
+ if ( this . testDir != null && Directory . Exists ( this . testDir ) )
33
+ {
34
+ Directory . Delete ( this . testDir , true ) ;
35
+ this . testDir = null ;
36
+ }
37
+
26
38
return this . container == null ? Task . CompletedTask : this . container . DisposeAsync ( ) . AsTask ( ) ;
27
39
}
28
40
@@ -40,11 +52,16 @@ public async Task ConnectionToAllServicesEstablished()
40
52
var blobProperties = await blobServiceClient . GetPropertiesAsync ( ) ;
41
53
var queueProperties = await queueServiceClient . GetPropertiesAsync ( ) ;
42
54
var tableServiceProperties = await tableServiceClient . GetPropertiesAsync ( ) ;
55
+ var workspaceCommandResult = await this . container . ExecAsync ( new List < string > { "ls" , AzuriteTestcontainerConfiguration . DefaultLocation } ) ;
43
56
44
57
// Then
45
58
Assert . True ( blobProperties . GetRawResponse ( ) . Status is >= 200 and <= 299 ) ;
46
59
Assert . True ( queueProperties . GetRawResponse ( ) . Status is >= 200 and <= 299 ) ;
47
60
Assert . True ( tableServiceProperties . GetRawResponse ( ) . Status is >= 200 and <= 299 ) ;
61
+ Assert . True ( workspaceCommandResult . ExitCode == 0 ) ;
62
+ Assert . Contains ( GetDataFilename ( "blob" ) , workspaceCommandResult . Stdout ) ;
63
+ Assert . Contains ( GetDataFilename ( "queue" ) , workspaceCommandResult . Stdout ) ;
64
+ Assert . Contains ( GetDataFilename ( "table" ) , workspaceCommandResult . Stdout ) ;
48
65
}
49
66
50
67
[ Fact ]
@@ -62,11 +79,16 @@ await this.StartAzuriteContainer(config =>
62
79
63
80
// When
64
81
var blobProperties = await blobServiceClient . GetPropertiesAsync ( ) ;
82
+ var workspaceCommandResult = await this . container . ExecAsync ( new List < string > { "ls" , AzuriteTestcontainerConfiguration . DefaultLocation } ) ;
65
83
66
84
// Then
67
85
Assert . True ( blobProperties . GetRawResponse ( ) . Status is >= 200 and <= 299 ) ;
68
86
await Assert . ThrowsAsync < RequestFailedException > ( ( ) => queueServiceClient . GetPropertiesAsync ( ) ) ;
69
87
await Assert . ThrowsAsync < RequestFailedException > ( ( ) => tableServiceClient . GetPropertiesAsync ( ) ) ;
88
+ Assert . True ( workspaceCommandResult . ExitCode == 0 ) ;
89
+ Assert . Contains ( GetDataFilename ( "blob" ) , workspaceCommandResult . Stdout ) ;
90
+ Assert . DoesNotContain ( GetDataFilename ( "queue" ) , workspaceCommandResult . Stdout ) ;
91
+ Assert . DoesNotContain ( GetDataFilename ( "table" ) , workspaceCommandResult . Stdout ) ;
70
92
}
71
93
72
94
[ Fact ]
@@ -84,11 +106,16 @@ await this.StartAzuriteContainer(config =>
84
106
85
107
// When
86
108
var queueProperties = await queueServiceClient . GetPropertiesAsync ( ) ;
109
+ var workspaceCommandResult = await this . container . ExecAsync ( new List < string > { "ls" , AzuriteTestcontainerConfiguration . DefaultLocation } ) ;
87
110
88
111
// Then
89
112
Assert . True ( queueProperties . GetRawResponse ( ) . Status is >= 200 and <= 299 ) ;
90
113
await Assert . ThrowsAsync < RequestFailedException > ( ( ) => blobServiceClient . GetPropertiesAsync ( ) ) ;
91
114
await Assert . ThrowsAsync < RequestFailedException > ( ( ) => tableServiceClient . GetPropertiesAsync ( ) ) ;
115
+ Assert . True ( workspaceCommandResult . ExitCode == 0 ) ;
116
+ Assert . DoesNotContain ( GetDataFilename ( "blob" ) , workspaceCommandResult . Stdout ) ;
117
+ Assert . Contains ( GetDataFilename ( "queue" ) , workspaceCommandResult . Stdout ) ;
118
+ Assert . DoesNotContain ( GetDataFilename ( "table" ) , workspaceCommandResult . Stdout ) ;
92
119
}
93
120
94
121
[ Fact ]
@@ -106,11 +133,36 @@ await this.StartAzuriteContainer(config =>
106
133
107
134
// When
108
135
var tableServiceProperties = await tableServiceClient . GetPropertiesAsync ( ) ;
136
+ var workspaceCommandResult = await this . container . ExecAsync ( new List < string > { "ls" , AzuriteTestcontainerConfiguration . DefaultLocation } ) ;
109
137
110
138
// Then
111
139
Assert . True ( tableServiceProperties . GetRawResponse ( ) . Status is >= 200 and <= 299 ) ;
112
140
await Assert . ThrowsAsync < RequestFailedException > ( ( ) => blobServiceClient . GetPropertiesAsync ( ) ) ;
113
141
await Assert . ThrowsAsync < RequestFailedException > ( ( ) => queueServiceClient . GetPropertiesAsync ( ) ) ;
142
+ Assert . True ( workspaceCommandResult . ExitCode == 0 ) ;
143
+ Assert . DoesNotContain ( GetDataFilename ( "blob" ) , workspaceCommandResult . Stdout ) ;
144
+ Assert . DoesNotContain ( GetDataFilename ( "queue" ) , workspaceCommandResult . Stdout ) ;
145
+ Assert . Contains ( GetDataFilename ( "table" ) , workspaceCommandResult . Stdout ) ;
146
+ }
147
+
148
+ [ Fact ]
149
+ public async Task BindedLocationPathShouldContainsDataFiles ( )
150
+ {
151
+ // Given
152
+ this . testDir = Path . Combine ( TempDir , Guid . NewGuid ( ) . ToString ( "N" ) ) ;
153
+ Directory . CreateDirectory ( this . testDir ) ;
154
+ await this . StartAzuriteContainer ( config =>
155
+ {
156
+ config . Location = this . testDir ;
157
+ } ) ;
158
+
159
+ // When
160
+
161
+ // Then
162
+ var files = Directory . GetFiles ( this . testDir ) ;
163
+ Assert . Contains ( files , file => file . EndsWith ( GetDataFilename ( "blob" ) , StringComparison . InvariantCultureIgnoreCase ) ) ;
164
+ Assert . Contains ( files , file => file . EndsWith ( GetDataFilename ( "queue" ) , StringComparison . InvariantCultureIgnoreCase ) ) ;
165
+ Assert . Contains ( files , file => file . EndsWith ( GetDataFilename ( "table" ) , StringComparison . InvariantCultureIgnoreCase ) ) ;
114
166
}
115
167
116
168
private async Task StartAzuriteContainer ( Action < AzuriteTestcontainerConfiguration > configure = null )
@@ -122,5 +174,10 @@ private async Task StartAzuriteContainer(Action<AzuriteTestcontainerConfiguratio
122
174
. Build ( ) ;
123
175
await this . container . StartAsync ( ) ;
124
176
}
177
+
178
+ private static string GetDataFilename ( string service )
179
+ {
180
+ return $ "__azurite_db_{ service } __.json";
181
+ }
125
182
}
126
183
}
0 commit comments