32
32
using Newtonsoft . Json . Linq ;
33
33
using StreamJsonRpc ;
34
34
35
- namespace Bicep . Cli . IntegrationTests ;
35
+ namespace Bicep . Cli . IntegrationTests . Commands ;
36
36
37
37
[ TestClass ]
38
- [ Ignore ( "Commented out temporarily to investigate ANSI assertion differences in CI" ) ]
39
38
public class LocalDeployCommandTests : TestBase
40
39
{
41
40
private static ExtensionPackage GetMockLocalDeployPackage ( BinaryData ? tgzData = null )
@@ -65,12 +64,8 @@ private static void RegisterExtensionMocks(
65
64
. AddSingleton ( armDeploymentProvider ) ;
66
65
}
67
66
68
- [ TestMethod ]
69
- public async Task Local_deploy_should_succeed ( )
67
+ private ILocalExtension GetExtensionMock ( )
70
68
{
71
- var paramFile = new EmbeddedFile ( typeof ( LocalDeployCommandTests ) . Assembly , "Files/LocalDeployCommandTests/weather/main.bicepparam" ) ;
72
- var baselineFolder = BaselineFolder . BuildOutputFolder ( TestContext , paramFile ) ;
73
-
74
69
var extensionMock = StrictMock . Of < ILocalExtension > ( ) ;
75
70
extensionMock . Setup ( x => x . CreateOrUpdate ( It . IsAny < ResourceSpecification > ( ) , It . IsAny < CancellationToken > ( ) ) )
76
71
. Returns < ResourceSpecification , CancellationToken > ( ( req , _ ) =>
@@ -118,25 +113,32 @@ public async Task Local_deploy_should_succeed()
118
113
return Task . FromResult ( new LocalExtensionOperationResponse ( new Resource ( req . Type , req . ApiVersion , req . Properties , ( outputProperties as JsonObject ) ! , "Succeeded" ) , null ) ) ;
119
114
} ) ;
120
115
116
+ return extensionMock . Object ;
117
+ }
118
+
119
+ [ TestMethod ]
120
+ public async Task Local_deploy_should_succeed ( )
121
+ {
122
+ var paramFile = new EmbeddedFile ( typeof ( LocalDeployCommandTests ) . Assembly , "Files/LocalDeployCommandTests/weather/main.bicepparam" ) ;
123
+ var baselineFolder = BaselineFolder . BuildOutputFolder ( TestContext , paramFile ) ;
121
124
122
125
var services = await ExtensionTestHelper . GetServiceBuilderWithPublishedExtension ( GetMockLocalDeployPackage ( ) , new ( LocalDeployEnabled : true ) ) ;
123
126
var clientFactory = services . Build ( ) . Construct < IContainerRegistryClientFactory > ( ) ;
124
127
125
128
var result = await Bicep (
126
129
new InvocationSettings ( ClientFactory : clientFactory ) ,
127
- services => RegisterExtensionMocks ( services , extensionMock . Object ) ,
130
+ services => RegisterExtensionMocks ( services , GetExtensionMock ( ) ) ,
128
131
TestContext . CancellationTokenSource . Token ,
129
132
[ "local-deploy" , baselineFolder . EntryFile . OutputFilePath ] ) ;
130
133
131
134
result . Should ( ) . NotHaveStderr ( ) . And . Succeed ( ) ;
132
- var output = GetOutputWithoutDurations ( result . Stdout ) ;
133
135
134
- output . Should ( ) . EqualIgnoringWhitespace ( """
136
+ result . WithoutAnsi ( ) . WithoutDurations ( ) . Stdout . Should ( ) . BeEquivalentToIgnoringNewlines ( """
135
137
╭───────────────┬──────────┬───────────╮
136
138
│ Resource │ Duration │ Status │
137
139
├───────────────┼──────────┼───────────┤
138
- │ gridpointsReq │ <snip> │ Succeeded │
139
- │ forecastReq │ <snip> │ Succeeded │
140
+ │ gridpointsReq │ │ Succeeded │
141
+ │ forecastReq │ │ Succeeded │
140
142
╰───────────────┴──────────┴───────────╯
141
143
╭────────────────┬────────────────────────────────╮
142
144
│ Output │ Value │
@@ -157,6 +159,47 @@ public async Task Local_deploy_should_succeed()
157
159
│ │ ] │
158
160
│ forecastString │ Forecast: Name │
159
161
╰────────────────┴────────────────────────────────╯
162
+
163
+ """ ) ;
164
+ }
165
+
166
+ [ TestMethod ]
167
+ public async Task Local_deploy_should_succeed_with_json_output ( )
168
+ {
169
+ var paramFile = new EmbeddedFile ( typeof ( LocalDeployCommandTests ) . Assembly , "Files/LocalDeployCommandTests/weather/main.bicepparam" ) ;
170
+ var baselineFolder = BaselineFolder . BuildOutputFolder ( TestContext , paramFile ) ;
171
+
172
+ var services = await ExtensionTestHelper . GetServiceBuilderWithPublishedExtension ( GetMockLocalDeployPackage ( ) , new ( LocalDeployEnabled : true ) ) ;
173
+ var clientFactory = services . Build ( ) . Construct < IContainerRegistryClientFactory > ( ) ;
174
+
175
+ var result = await Bicep (
176
+ new InvocationSettings ( ClientFactory : clientFactory ) ,
177
+ services => RegisterExtensionMocks ( services , GetExtensionMock ( ) ) ,
178
+ TestContext . CancellationTokenSource . Token ,
179
+ [ "local-deploy" , baselineFolder . EntryFile . OutputFilePath , "--format" , "json" ] ) ;
180
+
181
+ result . Should ( ) . NotHaveStderr ( ) . And . Succeed ( ) ;
182
+
183
+ result . Stdout . Should ( ) . DeepEqualJson ( """
184
+ {
185
+ "outputs": {
186
+ "forecast": [
187
+ {
188
+ "name": "Tonight",
189
+ "temperature": 47
190
+ },
191
+ {
192
+ "name": "Wednesday",
193
+ "temperature": 64
194
+ },
195
+ {
196
+ "name": "Wednesday Night",
197
+ "temperature": 46
198
+ }
199
+ ],
200
+ "forecastString": "Forecast: Name"
201
+ }
202
+ }
160
203
""" ) ;
161
204
}
162
205
@@ -233,13 +276,13 @@ public async Task Local_deploy_with_azure_should_succeed(bool async)
233
276
[ "local-deploy" , baselineFolder . EntryFile . OutputFilePath ] ) ;
234
277
235
278
result . Should ( ) . NotHaveStderr ( ) . And . Succeed ( ) ;
236
- var output = GetOutputWithoutDurations ( result . Stdout ) ;
237
- output . Should ( ) . EqualIgnoringWhitespace ( """
279
+
280
+ result . WithoutAnsi ( ) . WithoutDurations ( ) . Stdout . Should ( ) . BeEquivalentToIgnoringNewlines ( """
238
281
╭───────────────┬──────────┬───────────╮
239
282
│ Resource │ Duration │ Status │
240
283
├───────────────┼──────────┼───────────┤
241
- │ gridpointsReq │ <snip> │ Succeeded │
242
- │ gridCoords │ <snip> │ Succeeded │
284
+ │ gridpointsReq │ │ Succeeded │
285
+ │ gridCoords │ │ Succeeded │
243
286
╰───────────────┴──────────┴───────────╯
244
287
╭────────┬───────╮
245
288
│ Output │ Value │
@@ -249,7 +292,4 @@ public async Task Local_deploy_with_azure_should_succeed(bool async)
249
292
250
293
""" ) ;
251
294
}
252
-
253
- private static string GetOutputWithoutDurations ( string output )
254
- => Regex . Replace ( output , @"[ ]+\d+\.\d+s[ ]+" , " <snip> " ) ;
255
295
}
0 commit comments