Skip to content

Commit 697931e

Browse files
authored
Merge pull request #3225 from jasper-schneider/batchTests
Batch test cleanup/reorganization
2 parents c704298 + c50406c commit 697931e

File tree

155 files changed

+10261
-50556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+10261
-50556
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,27 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
618618
return response;
619619
}
620620

621+
/// <summary>
622+
/// Builds a JobListFromJobScheduleResponse object
623+
/// </summary>
624+
public static AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> CreateJobListFromJobScheduleResponse(IEnumerable<string> jobIds)
625+
{
626+
var response = new AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders>();
627+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
628+
629+
List<ProxyModels.CloudJob> jobs = new List<ProxyModels.CloudJob>();
630+
631+
foreach (string id in jobIds)
632+
{
633+
ProxyModels.CloudJob job = new ProxyModels.CloudJob(id: id);
634+
jobs.Add(job);
635+
}
636+
637+
response.Body = new MockPagedEnumerable<ProxyModels.CloudJob>(jobs);
638+
639+
return response;
640+
}
641+
621642
/// <summary>
622643
/// Builds a CloudTaskGetResponse object
623644
/// </summary>

src/ResourceManager/AzureBatch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 21 additions & 275 deletions
Large diffs are not rendered by default.

src/ResourceManager/AzureBatch/Commands.Batch.Test/ComputeNodeUsers/NewBatchComputeNodeUserCommandTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,40 @@ public void NewBatchComputeNodeUserParametersTest()
7070
// Verify no exceptions when required parameters are set
7171
cmdlet.ExecuteCmdlet();
7272
}
73+
74+
[Fact]
75+
[Trait(Category.AcceptanceType, Category.CheckIn)]
76+
public void NewBatchComputeNodeUserParametersGetPassedToRequestTest()
77+
{
78+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
79+
cmdlet.BatchContext = context;
80+
81+
cmdlet.PoolId = "testPool";
82+
cmdlet.ComputeNodeId = "computeNode1";
83+
cmdlet.Name = "user";
84+
cmdlet.Password = "password";
85+
cmdlet.IsAdmin = true;
86+
cmdlet.ExpiryTime = DateTime.Now.AddDays(30);
87+
88+
ProxyModels.ComputeNodeUser requestParameters = null;
89+
90+
// Store the request parameters
91+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
92+
ProxyModels.ComputeNodeUser,
93+
ProxyModels.ComputeNodeAddUserOptions,
94+
AzureOperationHeaderResponse<ProxyModels.ComputeNodeAddUserHeaders>>(requestAction: (r) =>
95+
{
96+
requestParameters = r.Parameters;
97+
});
98+
99+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
100+
cmdlet.ExecuteCmdlet();
101+
102+
// Verify the request parameters match the cmdlet parameters
103+
Assert.Equal(cmdlet.Name, requestParameters.Name);
104+
Assert.Equal(cmdlet.Password, requestParameters.Password);
105+
Assert.Equal(cmdlet.IsAdmin, requestParameters.IsAdmin);
106+
Assert.Equal(cmdlet.ExpiryTime, requestParameters.ExpiryTime);
107+
}
73108
}
74109
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/JobSchedules/NewBatchJobScheduleCommandTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Moq;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Linq;
2324
using System.Management.Automation;
2425
using Xunit;
2526
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
@@ -66,5 +67,76 @@ public void NewBatchJobScheduleParametersTest()
6667
// Verify no exceptions when required parameters are set
6768
cmdlet.ExecuteCmdlet();
6869
}
70+
71+
[Fact]
72+
[Trait(Category.AcceptanceType, Category.CheckIn)]
73+
public void NewBatchJobScheduleParametersGetPassedToRequestTest()
74+
{
75+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
76+
cmdlet.BatchContext = context;
77+
78+
cmdlet.Id = "testJobSchedule";
79+
cmdlet.DisplayName = "display name";
80+
Models.PSJobSpecification jobSpec = new Models.PSJobSpecification()
81+
{
82+
DisplayName = "job display name",
83+
CommonEnvironmentSettings = new List<Models.PSEnvironmentSetting>()
84+
{
85+
new Models.PSEnvironmentSetting("common1", "val1"),
86+
new Models.PSEnvironmentSetting("common2", "val2")
87+
},
88+
JobManagerTask = new Models.PSJobManagerTask("job manager", "cmd /c echo job manager"),
89+
JobPreparationTask = new Models.PSJobPreparationTask("cmd /c echo job prep"),
90+
JobReleaseTask = new Models.PSJobReleaseTask("cmd /c echo job release"),
91+
PoolInformation = new Models.PSPoolInformation()
92+
{
93+
PoolId = "myPool"
94+
}
95+
};
96+
cmdlet.JobSpecification = jobSpec;
97+
Models.PSSchedule schedule = new Models.PSSchedule()
98+
{
99+
DoNotRunAfter = DateTime.Now.AddYears(1),
100+
DoNotRunUntil = DateTime.Now.AddDays(1),
101+
RecurrenceInterval = TimeSpan.FromDays(1),
102+
StartWindow = TimeSpan.FromHours(1)
103+
};
104+
cmdlet.Schedule = schedule;
105+
cmdlet.Metadata = new Dictionary<string, string>();
106+
cmdlet.Metadata.Add("meta1", "value1");
107+
cmdlet.Metadata.Add("meta2", "value2");
108+
109+
JobScheduleAddParameter requestParameters = null;
110+
111+
// Store the request parameters
112+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
113+
JobScheduleAddParameter,
114+
JobScheduleAddOptions,
115+
AzureOperationHeaderResponse<JobScheduleAddHeaders>>(requestAction: (r) =>
116+
{
117+
requestParameters = r.Parameters;
118+
});
119+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
120+
cmdlet.ExecuteCmdlet();
121+
122+
// Verify the request parameters match the cmdlet parameters
123+
Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
124+
Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count);
125+
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name);
126+
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value);
127+
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name);
128+
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value);
129+
Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id);
130+
Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine);
131+
Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine);
132+
Assert.Equal(jobSpec.PoolInformation.PoolId, requestParameters.JobSpecification.PoolInfo.PoolId);
133+
Assert.Equal(schedule.DoNotRunAfter, requestParameters.Schedule.DoNotRunAfter);
134+
Assert.Equal(schedule.DoNotRunUntil, requestParameters.Schedule.DoNotRunUntil);
135+
Assert.Equal(schedule.RecurrenceInterval, requestParameters.Schedule.RecurrenceInterval);
136+
Assert.Equal(schedule.StartWindow, requestParameters.Schedule.StartWindow);
137+
Assert.Equal(cmdlet.Metadata.Count, requestParameters.Metadata.Count);
138+
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[0].Name], requestParameters.Metadata[0].Value);
139+
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[1].Name], requestParameters.Metadata[1].Value);
140+
}
69141
}
70142
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/JobSchedules/SetBatchJobScheduleCommandTests.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2121
using Moq;
2222
using System;
23+
using System.Collections.Generic;
2324
using System.Management.Automation;
2425
using Xunit;
2526
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
@@ -65,5 +66,78 @@ public void SetBatchJobScheduleParametersTest()
6566
// Verify that no exceptions occur
6667
cmdlet.ExecuteCmdlet();
6768
}
69+
70+
[Fact]
71+
[Trait(Category.AcceptanceType, Category.CheckIn)]
72+
public void SetBatchJobScheduleParametersGetPassedToRequestTest()
73+
{
74+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
75+
cmdlet.BatchContext = context;
76+
77+
cmdlet.JobSchedule = new PSCloudJobSchedule(BatchTestHelpers.CreateFakeBoundJobSchedule(context));
78+
79+
// Make changes to the job schedule
80+
PSJobSpecification jobSpec = new PSJobSpecification()
81+
{
82+
DisplayName = "job display name",
83+
CommonEnvironmentSettings = new List<PSEnvironmentSetting>()
84+
{
85+
new PSEnvironmentSetting("common1", "val1"),
86+
new PSEnvironmentSetting("common2", "val2")
87+
},
88+
JobManagerTask = new PSJobManagerTask("job manager", "cmd /c echo job manager"),
89+
JobPreparationTask = new PSJobPreparationTask("cmd /c echo job prep"),
90+
JobReleaseTask = new PSJobReleaseTask("cmd /c echo job release"),
91+
PoolInformation = new PSPoolInformation()
92+
{
93+
PoolId = "myPool"
94+
}
95+
};
96+
cmdlet.JobSchedule.JobSpecification = jobSpec;
97+
98+
PSSchedule schedule = new PSSchedule()
99+
{
100+
DoNotRunAfter = DateTime.Now.AddYears(1),
101+
DoNotRunUntil = DateTime.Now.AddDays(1),
102+
RecurrenceInterval = TimeSpan.FromDays(1),
103+
StartWindow = TimeSpan.FromHours(1)
104+
};
105+
cmdlet.JobSchedule.Schedule = schedule;
106+
107+
cmdlet.JobSchedule.Metadata = new List<PSMetadataItem>()
108+
{
109+
new PSMetadataItem("metadata1", "value1")
110+
};
111+
112+
// Store the request parameters
113+
JobScheduleUpdateParameter requestParameters = null;
114+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
115+
JobScheduleUpdateParameter,
116+
JobScheduleUpdateOptions,
117+
AzureOperationHeaderResponse<JobScheduleUpdateHeaders>>(requestAction: (r) =>
118+
{
119+
requestParameters = r.Parameters;
120+
});
121+
cmdlet.AdditionalBehaviors = new BatchClientBehavior[] { interceptor };
122+
cmdlet.ExecuteCmdlet();
123+
124+
// Verify that the request parameters contain the updated properties
125+
Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count);
126+
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name);
127+
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value);
128+
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name);
129+
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value);
130+
Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id);
131+
Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine);
132+
Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine);
133+
Assert.Equal(jobSpec.PoolInformation.PoolId, requestParameters.JobSpecification.PoolInfo.PoolId);
134+
Assert.Equal(schedule.DoNotRunAfter, requestParameters.Schedule.DoNotRunAfter);
135+
Assert.Equal(schedule.DoNotRunUntil, requestParameters.Schedule.DoNotRunUntil);
136+
Assert.Equal(schedule.RecurrenceInterval, requestParameters.Schedule.RecurrenceInterval);
137+
Assert.Equal(schedule.StartWindow, requestParameters.Schedule.StartWindow);
138+
Assert.Equal(cmdlet.JobSchedule.Metadata.Count, requestParameters.Metadata.Count);
139+
Assert.Equal(cmdlet.JobSchedule.Metadata[0].Name, requestParameters.Metadata[0].Name);
140+
Assert.Equal(cmdlet.JobSchedule.Metadata[0].Value, requestParameters.Metadata[0].Value);
141+
}
68142
}
69143
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/Jobs/GetBatchJobCommandTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,43 @@ public void ListJobsMaxCountTest()
241241
Assert.Equal(idsOfConstructedJobs.Length, pipeline.Count);
242242
}
243243

244+
[Fact]
245+
[Trait(Category.AcceptanceType, Category.CheckIn)]
246+
public void ListBatchJobsUnderScheduleTest()
247+
{
248+
// Setup cmdlet to list jobs without filters.
249+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
250+
cmdlet.BatchContext = context;
251+
cmdlet.JobScheduleId = "jobSchedule";
252+
253+
string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" };
254+
255+
// Build some CloudJobs instead of querying the service on a List Jobs from Job Schedule call
256+
AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> response =
257+
BatchTestHelpers.CreateJobListFromJobScheduleResponse(idsOfConstructedJobs);
258+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.JobListFromJobScheduleOptions,
259+
AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders>>(response);
260+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
261+
262+
// Setup the cmdlet to write pipeline output to a list that can be examined later
263+
List<PSCloudJob> pipeline = new List<PSCloudJob>();
264+
commandRuntimeMock.Setup(r =>
265+
r.WriteObject(It.IsAny<PSCloudJob>()))
266+
.Callback<object>(j => pipeline.Add((PSCloudJob)j));
267+
268+
cmdlet.ExecuteCmdlet();
269+
270+
// Verify that the cmdlet wrote the constructed jobs to the pipeline
271+
Assert.Equal(3, pipeline.Count);
272+
int jobCount = 0;
273+
foreach (PSCloudJob j in pipeline)
274+
{
275+
Assert.True(idsOfConstructedJobs.Contains(j.Id));
276+
jobCount++;
277+
}
278+
Assert.Equal(idsOfConstructedJobs.Length, jobCount);
279+
}
280+
244281
[Fact]
245282
[Trait(Category.AcceptanceType, Category.CheckIn)]
246283
public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped()

src/ResourceManager/AzureBatch/Commands.Batch.Test/Jobs/NewBatchJobCommandTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,61 @@ public void NewBatchJobParametersTest()
7575
cmdlet.ExecuteCmdlet();
7676
}
7777

78+
[Fact]
79+
[Trait(Category.AcceptanceType, Category.CheckIn)]
80+
public void NewBatchJobParametersGetPassedToRequestTest()
81+
{
82+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
83+
cmdlet.BatchContext = context;
84+
85+
cmdlet.Id = "testJob";
86+
cmdlet.DisplayName = "display name";
87+
cmdlet.CommonEnvironmentSettings = new Dictionary<string, string>();
88+
cmdlet.CommonEnvironmentSettings.Add("commonEnv1", "value1");
89+
cmdlet.Constraints = new PSJobConstraints(TimeSpan.FromHours(1), 5);
90+
cmdlet.JobManagerTask = new PSJobManagerTask("job manager", "cmd /c echo job manager");
91+
cmdlet.JobPreparationTask = new PSJobPreparationTask("cmd /c echo job prep");
92+
cmdlet.JobReleaseTask = new PSJobReleaseTask("cmd /c echo job release");
93+
cmdlet.PoolInformation = new PSPoolInformation()
94+
{
95+
PoolId = "myPool"
96+
};
97+
cmdlet.Priority = 2;
98+
cmdlet.Metadata = new Dictionary<string, string>();
99+
cmdlet.Metadata.Add("meta1", "value1");
100+
cmdlet.Metadata.Add("meta2", "value2");
101+
cmdlet.UsesTaskDependencies = true;
102+
103+
JobAddParameter requestParameters = null;
104+
105+
// Store the request parameters
106+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
107+
JobAddParameter,
108+
JobAddOptions,
109+
AzureOperationHeaderResponse<JobAddHeaders>>(requestAction: (r) =>
110+
{
111+
requestParameters = r.Parameters;
112+
});
113+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
114+
cmdlet.ExecuteCmdlet();
115+
116+
// Verify the request parameters match the cmdlet parameters
117+
Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
118+
Assert.Equal(cmdlet.CommonEnvironmentSettings.Count, requestParameters.CommonEnvironmentSettings.Count);
119+
Assert.Equal(cmdlet.CommonEnvironmentSettings[requestParameters.CommonEnvironmentSettings[0].Name], requestParameters.CommonEnvironmentSettings[0].Value);
120+
Assert.Equal(cmdlet.Constraints.MaxTaskRetryCount, requestParameters.Constraints.MaxTaskRetryCount);
121+
Assert.Equal(cmdlet.Constraints.MaxWallClockTime, requestParameters.Constraints.MaxWallClockTime);
122+
Assert.Equal(cmdlet.JobManagerTask.Id, requestParameters.JobManagerTask.Id);
123+
Assert.Equal(cmdlet.JobPreparationTask.CommandLine, requestParameters.JobPreparationTask.CommandLine);
124+
Assert.Equal(cmdlet.JobReleaseTask.CommandLine, requestParameters.JobReleaseTask.CommandLine);
125+
Assert.Equal(cmdlet.PoolInformation.PoolId, requestParameters.PoolInfo.PoolId);
126+
Assert.Equal(cmdlet.Priority, requestParameters.Priority);
127+
Assert.Equal(cmdlet.Metadata.Count, requestParameters.Metadata.Count);
128+
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[0].Name], requestParameters.Metadata[0].Value);
129+
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[1].Name], requestParameters.Metadata[1].Value);
130+
Assert.Equal(cmdlet.UsesTaskDependencies, requestParameters.UsesTaskDependencies);
131+
}
132+
78133
[Fact]
79134
[Trait(Category.AcceptanceType, Category.CheckIn)]
80135
public void ApplicationPackageReferencesAreSentToService()

0 commit comments

Comments
 (0)