@@ -225,6 +225,7 @@ function Test-GetDeploymentScriptLog-PowerShell
225
225
$deployment = New-AzResourceGroupDeployment - Name $rname - ResourceGroupName $rgname - TemplateFile TemplateScriptDeployment.json - TemplateParameterFile TemplateScriptDeploymentParameters.json
226
226
$deploymentScriptName = " PsTest-DeploymentScripts-" + $deployment.parameters.scriptSuffix.Value
227
227
$resourceId = " /subscriptions/$subId /resourcegroups/$rgname /providers/Microsoft.Resources/deploymentScripts/$deploymentScriptName "
228
+ $tailInteger = 5
228
229
229
230
# Test - GetLogByNameAndResourceGroup
230
231
$getLogByNameAndResourceGroup = Get-AzDeploymentScriptLog - ResourceGroupName $rgname - Name $deploymentScriptName
@@ -235,13 +236,34 @@ function Test-GetDeploymentScriptLog-PowerShell
235
236
Assert-AreEqual $deploymentScriptName $getLogByNameAndResourceGroup.DeploymentScriptName
236
237
237
238
239
+ # Test - GetLogByNameAndResourceGroup - WithTailParameter
240
+ $getLogByNameAndResourceGroupWithTail = Get-AzDeploymentScriptLog - ResourceGroupName $rgname - Name $deploymentScriptName - Tail $tailInteger
241
+ $tail = [math ]::min( ($getLogByNameAndResourceGroup.Log -split ' \n' ).count, $tailInteger )
242
+
243
+ # Assert
244
+ Assert-NotNull $getLogByNameAndResourceGroupWithTail
245
+ Assert-NotNull $deploymentScriptName $getLogByNameAndResourceGroupWithTail.Log
246
+ Assert-AreEqual $deploymentScriptName $getLogByNameAndResourceGroupWithTail.DeploymentScriptName
247
+ Assert-AreEqual ($getLogByNameAndResourceGroupWithTail.Log -split ' \n' ).count $tail
248
+
249
+
238
250
# Test - GetLogByDeploymentScriptResourceId
239
251
$getLogByResourceId = Get-AzDeploymentScriptLog - DeploymentScriptResourceId $resourceId
240
252
241
253
# Assert
242
254
Assert-NotNull $getLogByResourceId
243
255
Assert-NotNull $deploymentScriptName $getLogByResourceId.Log
244
256
Assert-AreEqual $deploymentScriptName $getLogByResourceId.DeploymentScriptName
257
+
258
+ # Test - GetLogByDeploymentScriptResourceId - WithTailParameter
259
+ $getLogByResourceIdWithTail = Get-AzDeploymentScriptLog - DeploymentScriptResourceId $resourceId - Tail $tailInteger
260
+ $tail = [math ]::min( ($getLogByResourceId.Log -split ' \n' ).count, $tailInteger )
261
+
262
+ # Assert
263
+ Assert-NotNull $getLogByResourceIdWithTail
264
+ Assert-NotNull $deploymentScriptName $getLogByResourceIdWithTail.Log
265
+ Assert-AreEqual $deploymentScriptName $getLogByResourceIdWithTail.DeploymentScriptName
266
+ Assert-AreEqual ($getLogByResourceIdWithTail.Log -split ' \n' ).count $tail
245
267
246
268
247
269
# Test - GetLogByInputObject
@@ -252,6 +274,17 @@ function Test-GetDeploymentScriptLog-PowerShell
252
274
Assert-NotNull $getLogByInputObject
253
275
Assert-NotNull $deploymentScriptName $getLogByInputObject.Log
254
276
Assert-AreEqual $deploymentScriptName $getLogByInputObject.DeploymentScriptName
277
+
278
+ # Test - GetLogByInputObject - WithTailParameter
279
+ $deploymentScript = Get-AzDeploymentScript - ResourceGroupName $rgname - Name $deploymentScriptName
280
+ $getLogByInputObjectWithTail = Get-AzDeploymentScriptLog - DeploymentScriptInputObject $deploymentScript - Tail $tailInteger
281
+ $tail = [math ]::min( ($getLogByInputObject.Log -split ' \n' ).count, $tailInteger )
282
+
283
+ # Assert
284
+ Assert-NotNull $getLogByInputObjectWithTail
285
+ Assert-NotNull $deploymentScriptName $getLogByInputObjectWithTail.Log
286
+ Assert-AreEqual $deploymentScriptName $getLogByInputObjectWithTail.DeploymentScriptName
287
+ Assert-AreEqual ($getLogByResourceIdWithTail.Log -split ' \n' ).count $tail
255
288
}
256
289
finally
257
290
{
@@ -280,15 +313,30 @@ function Test-GetDeploymentScriptLog-Cli
280
313
$deployment = New-AzResourceGroupDeployment - Name $rname - ResourceGroupName $rgname - TemplateFile TemplateScriptDeploymentCli.json - TemplateParameterFile TemplateScriptDeploymentParametersCli.json
281
314
$deploymentScriptName = " PsTest-DeploymentScripts-" + $deployment.parameters.scriptSuffix.Value
282
315
$resourceId = " /subscriptions/$subId /resourcegroups/$rgname /providers/Microsoft.Resources/deploymentScripts/$deploymentScriptName "
316
+ $tailInteger = 2
283
317
284
318
# Test - GetLogByNameAndResourceGroup
285
- $getLogByNameAndResourceGroup = Get-AzDeploymentScriptLog - ResourceGroupName $rgname - Name $deploymentScriptName
319
+ $getLogByNameAndResourceGroup = Get-AzDeploymentScriptLog - ResourceGroupName $rgname - Name $deploymentScriptName
286
320
287
321
# Assert
288
322
Assert-NotNull $getLogByNameAndResourceGroup
289
323
Assert-NotNull $deploymentScriptName $getLogByNameAndResourceGroup.Log
290
324
Assert-AreEqual $deploymentScriptName $getLogByNameAndResourceGroup.DeploymentScriptName
291
325
326
+ # Test - GetLogByNameAndResourceGroup - WithTailParameter
327
+ $getLogByNameAndResourceGroupWithTail = Get-AzDeploymentScriptLog - ResourceGroupName $rgname - Name $deploymentScriptName - Tail $tailInteger
328
+
329
+ # \r is used in the template deployment script to denote line breaks in the CLI log output
330
+ $tail = [math ]::min( ($getLogByNameAndResourceGroup.Log -split ' \r' ).count, $tailInteger )
331
+
332
+ # Assert
333
+ Assert-NotNull $getLogByNameAndResourceGroupWithTail
334
+ Assert-NotNull $deploymentScriptName $getLogByNameAndResourceGroupWithTail.Log
335
+ Assert-AreEqual $deploymentScriptName $getLogByNameAndResourceGroupWithTail.DeploymentScriptName
336
+
337
+ # Counting \n instead of \r as every instance of \r is replaced with \n when the backend processes the Tail parameter.
338
+ Assert-AreEqual ($getLogByNameAndResourceGroupWithTail.Log -split ' \n' ).count $tail
339
+
292
340
# Test - GetLogByDeploymentScriptResourceId
293
341
$getLogByResourceId = Get-AzDeploymentScriptLog - DeploymentScriptResourceId $resourceId
294
342
@@ -298,6 +346,17 @@ function Test-GetDeploymentScriptLog-Cli
298
346
Assert-AreEqual $deploymentScriptName $getLogByResourceId.DeploymentScriptName
299
347
300
348
349
+ # Test - GetLogByDeploymentScriptResourceId - WithTailParameter
350
+ $getLogByResourceIdWithTail = Get-AzDeploymentScriptLog - DeploymentScriptResourceId $resourceId - Tail $tailInteger
351
+ $tail = [math ]::min( ($getLogByResourceId.Log -split ' \r' ).count, $tailInteger )
352
+
353
+ # Assert
354
+ Assert-NotNull $getLogByResourceIdWithTail
355
+ Assert-NotNull $deploymentScriptName $getLogByResourceIdWithTail.Log
356
+ Assert-AreEqual $deploymentScriptName $getLogByResourceIdWithTail.DeploymentScriptName
357
+ Assert-AreEqual ($getLogByResourceIdWithTail.Log -split ' \n' ).count $tail
358
+
359
+
301
360
# Test - GetLogByInputObject
302
361
$deploymentScript = Get-AzDeploymentScript - ResourceGroupName $rgname - Name $deploymentScriptName
303
362
$getLogByInputObject = Get-AzDeploymentScriptLog - DeploymentScriptInputObject $deploymentScript
@@ -306,6 +365,18 @@ function Test-GetDeploymentScriptLog-Cli
306
365
Assert-NotNull $getLogByInputObject
307
366
Assert-NotNull $deploymentScriptName $getLogByInputObject.Log
308
367
Assert-AreEqual $deploymentScriptName $getLogByInputObject.DeploymentScriptName
368
+
369
+
370
+ # Test - GetLogByInputObject - WithTailParameter
371
+ $deploymentScript = Get-AzDeploymentScript - ResourceGroupName $rgname - Name $deploymentScriptName
372
+ $getLogByInputObjectWithTail = Get-AzDeploymentScriptLog - DeploymentScriptInputObject $deploymentScript - Tail $tailInteger
373
+ $tail = [math ]::min( ($getLogByResourceId.Log -split ' \r' ).count, $tailInteger )
374
+
375
+ # Assert
376
+ Assert-NotNull $getLogByInputObjectWithTail
377
+ Assert-NotNull $deploymentScriptName $getLogByInputObjectWithTail.Log
378
+ Assert-AreEqual $deploymentScriptName $getLogByInputObjectWithTail.DeploymentScriptName
379
+ Assert-AreEqual ($getLogByInputObjectWithTail.Log -split ' \n' ).count $tail
309
380
}
310
381
finally
311
382
{
@@ -323,6 +394,7 @@ function Test-PipeDeploymentScriptObjectToGetLogs
323
394
$rgname = Get-ResourceGroupName
324
395
$rname = Get-ResourceName
325
396
$rglocation = " West US 2"
397
+ $tailInteger = 2
326
398
327
399
try
328
400
{
@@ -340,6 +412,17 @@ function Test-PipeDeploymentScriptObjectToGetLogs
340
412
Assert-NotNull $getLogByInputObject
341
413
Assert-NotNull $deploymentScriptName $getLogByInputObject.Log
342
414
Assert-AreEqual $deploymentScriptName $getLogByInputObject.DeploymentScriptName
415
+
416
+
417
+ # Test - GetLogsByInputObjectPiped - WithTailParameter
418
+ $getLogByInputObjectWithTail = Get-AzDeploymentScript - ResourceGroupName $rgname - Name $deploymentScriptName | Get-AzDeploymentScriptLog - Tail $tailInteger
419
+ $tail = [math ]::min( ($getLogByInputObject.Log -split ' \r' ).count, $tailInteger )
420
+
421
+ # Assert
422
+ Assert-NotNull $getLogByInputObjectWithTail
423
+ Assert-NotNull $deploymentScriptName $getLogByInputObjectWithTail.Log
424
+ Assert-AreEqual $deploymentScriptName $getLogByInputObjectWithTail.DeploymentScriptName
425
+ Assert-AreEqual ($getLogByInputObjectWithTail.Log -split ' \n' ).count $tail
343
426
}
344
427
finally
345
428
{
@@ -359,6 +442,7 @@ function Test-TrySaveNonExistingFilePathForLogFile
359
442
$rname = Get-ResourceName
360
443
$rglocation = " West US 2"
361
444
$badPath = " bad-path"
445
+ $tailInteger = 3
362
446
363
447
try
364
448
{
@@ -379,7 +463,8 @@ function Test-TrySaveNonExistingFilePathForLogFile
379
463
$path = (Get-Item " .\" ).FullName
380
464
$fullPath = Join-Path $path $badPath
381
465
$exceptionMessage = " Cannot find path '$fullPath '"
382
- Assert-Throws { Save-AzDeploymentScriptLog - DeploymentScriptInputObject $deploymentScript - OutputPath $badPath } $exceptionMessage
466
+ Assert-Throws { Save-AzDeploymentScriptLog - DeploymentScriptInputObject $deploymentScript - OutputPath $badPath } $exceptionMessage
467
+ Assert-Throws { Save-AzDeploymentScriptLog - DeploymentScriptInputObject $deploymentScript - OutputPath $badPath - Tail $tailInteger } $exceptionMessage
383
468
}
384
469
finally
385
470
{
0 commit comments