Skip to content

Commit a4b5080

Browse files
committed
Fix bug with New-AzureBatchTask -Tasks parameter
- This fixes #9912.
1 parent be48054 commit a4b5080

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/Batch/Batch.Test/Tasks/NewBatchTaskCommandTests.cs

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ public void ApplicationPackageReferencesAreSentOnATask()
178178
cmdlet.ExecuteCmdlet();
179179
}
180180

181-
private void ExitConditionsAreSentToService()
181+
[Fact]
182+
[Trait(Category.AcceptanceType, Category.CheckIn)]
183+
public void ExitConditionsAreSentToService()
182184
{
183185
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
184186
cmdlet.BatchContext = context;
@@ -317,11 +319,65 @@ public void NewBatchTaskCollectionParametersTest()
317319

318320
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
319321

320-
string[] taskIds = new[] {"simple1", "simple2"};
321-
PSCloudTask expected1 = new PSCloudTask(taskIds[0], commandLine);
322-
PSCloudTask expected2 = new PSCloudTask(taskIds[1], commandLine);
322+
const string pattern = @"**\*.txt";
323+
const string containerUrl = "containerUrl";
324+
const string path = "path";
325+
const OutputFileUploadCondition uploadCondition = OutputFileUploadCondition.TaskCompletion;
323326

324-
cmdlet.Tasks = new PSCloudTask[] {expected1, expected2};
327+
string[] taskIds = new[] { "simple1", "simple2" };
328+
PSCloudTask[] tasks = taskIds.Select(
329+
id => new PSCloudTask(id, commandLine)
330+
{
331+
ResourceFiles = new[]
332+
{
333+
new PSResourceFile(ResourceFile.FromUrl("anotherFile.txt", "https://another.blob"))
334+
},
335+
OutputFiles = new[]
336+
{
337+
new PSOutputFile(
338+
pattern,
339+
new PSOutputFileDestination(new PSOutputFileBlobContainerDestination(containerUrl, path)),
340+
new PSOutputFileUploadOptions(uploadCondition))
341+
},
342+
ApplicationPackageReferences = new[]
343+
{
344+
new PSApplicationPackageReference
345+
{
346+
ApplicationId = "1",
347+
Version = "foo"
348+
}
349+
},
350+
ExitConditions = new PSExitConditions()
351+
{
352+
ExitCodeRanges = new List<PSExitCodeRangeMapping>
353+
{
354+
new PSExitCodeRangeMapping(
355+
5,
356+
10,
357+
new PSExitOptions
358+
{
359+
DependencyAction = Azure.Batch.Common.DependencyAction.Block
360+
})
361+
362+
},
363+
ExitCodes = new List<PSExitCodeMapping>
364+
{
365+
new PSExitCodeMapping(
366+
11,
367+
new PSExitOptions
368+
{
369+
DependencyAction = Azure.Batch.Common.DependencyAction.Block
370+
})
371+
372+
},
373+
Default = new PSExitOptions
374+
{
375+
DependencyAction = Azure.Batch.Common.DependencyAction.Satisfy
376+
}
377+
}
378+
}).ToArray();
379+
380+
cmdlet.Tasks = tasks;
325381

326382
IList<TaskAddParameter> requestCollection = null;
327383

@@ -349,6 +405,18 @@ public void NewBatchTaskCollectionParametersTest()
349405
foreach (var task in requestCollection)
350406
{
351407
Assert.Contains(task.Id, taskIds);
408+
Assert.NotNull(task.ResourceFiles);
409+
Assert.NotEmpty(task.ResourceFiles);
410+
Assert.NotNull(task.OutputFiles);
411+
Assert.NotEmpty(task.OutputFiles);
412+
Assert.NotNull(task.ApplicationPackageReferences);
413+
Assert.NotEmpty(task.ApplicationPackageReferences);
414+
415+
Assert.NotNull(task.ExitConditions.ExitCodeRanges);
416+
Assert.NotEmpty(task.ExitConditions.ExitCodeRanges);
417+
Assert.NotNull(task.ExitConditions.ExitCodes);
418+
Assert.NotEmpty(task.ExitConditions.ExitCodes);
419+
Assert.NotNull(task.ExitConditions.DefaultProperty);
352420
}
353421
}
354422

src/Batch/Batch/Utils/Utils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ internal static void CloudTaskSyncCollections(PSCloudTask task)
258258
ConvertEnvironmentSetting);
259259

260260
task.omObject.ResourceFiles = CreateSyncedList(task.ResourceFiles, ConvertResourceFile);
261+
task.omObject.OutputFiles = CreateSyncedList(task.OutputFiles, ps => ps.omObject);
262+
task.omObject.ApplicationPackageReferences = CreateSyncedList(task.ApplicationPackageReferences, ps => ps.omObject);
263+
ExitConditionsSyncCollections(task.ExitConditions);
261264

262265
MultiInstanceSettingsSyncCollections(task.MultiInstanceSettings);
263266
}

0 commit comments

Comments
 (0)