Skip to content

Batch test cleanup/reorganization #3225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,27 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
return response;
}

/// <summary>
/// Builds a JobListFromJobScheduleResponse object
/// </summary>
public static AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> CreateJobListFromJobScheduleResponse(IEnumerable<string> jobIds)
{
var response = new AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders>();
response.Response = new HttpResponseMessage(HttpStatusCode.OK);

List<ProxyModels.CloudJob> jobs = new List<ProxyModels.CloudJob>();

foreach (string id in jobIds)
{
ProxyModels.CloudJob job = new ProxyModels.CloudJob(id: id);
jobs.Add(job);
}

response.Body = new MockPagedEnumerable<ProxyModels.CloudJob>(jobs);

return response;
}

/// <summary>
/// Builds a CloudTaskGetResponse object
/// </summary>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,40 @@ public void NewBatchComputeNodeUserParametersTest()
// Verify no exceptions when required parameters are set
cmdlet.ExecuteCmdlet();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewBatchComputeNodeUserParametersGetPassedToRequestTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

cmdlet.PoolId = "testPool";
cmdlet.ComputeNodeId = "computeNode1";
cmdlet.Name = "user";
cmdlet.Password = "password";
cmdlet.IsAdmin = true;
cmdlet.ExpiryTime = DateTime.Now.AddDays(30);

ProxyModels.ComputeNodeUser requestParameters = null;

// Store the request parameters
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
ProxyModels.ComputeNodeUser,
ProxyModels.ComputeNodeAddUserOptions,
AzureOperationHeaderResponse<ProxyModels.ComputeNodeAddUserHeaders>>(requestAction: (r) =>
{
requestParameters = r.Parameters;
});

cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
cmdlet.ExecuteCmdlet();

// Verify the request parameters match the cmdlet parameters
Assert.Equal(cmdlet.Name, requestParameters.Name);
Assert.Equal(cmdlet.Password, requestParameters.Password);
Assert.Equal(cmdlet.IsAdmin, requestParameters.IsAdmin);
Assert.Equal(cmdlet.ExpiryTime, requestParameters.ExpiryTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
Expand Down Expand Up @@ -66,5 +67,76 @@ public void NewBatchJobScheduleParametersTest()
// Verify no exceptions when required parameters are set
cmdlet.ExecuteCmdlet();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewBatchJobScheduleParametersGetPassedToRequestTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

cmdlet.Id = "testJobSchedule";
cmdlet.DisplayName = "display name";
Models.PSJobSpecification jobSpec = new Models.PSJobSpecification()
{
DisplayName = "job display name",
CommonEnvironmentSettings = new List<Models.PSEnvironmentSetting>()
{
new Models.PSEnvironmentSetting("common1", "val1"),
new Models.PSEnvironmentSetting("common2", "val2")
},
JobManagerTask = new Models.PSJobManagerTask("job manager", "cmd /c echo job manager"),
JobPreparationTask = new Models.PSJobPreparationTask("cmd /c echo job prep"),
JobReleaseTask = new Models.PSJobReleaseTask("cmd /c echo job release"),
PoolInformation = new Models.PSPoolInformation()
{
PoolId = "myPool"
}
};
cmdlet.JobSpecification = jobSpec;
Models.PSSchedule schedule = new Models.PSSchedule()
{
DoNotRunAfter = DateTime.Now.AddYears(1),
DoNotRunUntil = DateTime.Now.AddDays(1),
RecurrenceInterval = TimeSpan.FromDays(1),
StartWindow = TimeSpan.FromHours(1)
};
cmdlet.Schedule = schedule;
cmdlet.Metadata = new Dictionary<string, string>();
cmdlet.Metadata.Add("meta1", "value1");
cmdlet.Metadata.Add("meta2", "value2");

JobScheduleAddParameter requestParameters = null;

// Store the request parameters
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
JobScheduleAddParameter,
JobScheduleAddOptions,
AzureOperationHeaderResponse<JobScheduleAddHeaders>>(requestAction: (r) =>
{
requestParameters = r.Parameters;
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
cmdlet.ExecuteCmdlet();

// Verify the request parameters match the cmdlet parameters
Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count);
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name);
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value);
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name);
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value);
Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id);
Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine);
Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine);
Assert.Equal(jobSpec.PoolInformation.PoolId, requestParameters.JobSpecification.PoolInfo.PoolId);
Assert.Equal(schedule.DoNotRunAfter, requestParameters.Schedule.DoNotRunAfter);
Assert.Equal(schedule.DoNotRunUntil, requestParameters.Schedule.DoNotRunUntil);
Assert.Equal(schedule.RecurrenceInterval, requestParameters.Schedule.RecurrenceInterval);
Assert.Equal(schedule.StartWindow, requestParameters.Schedule.StartWindow);
Assert.Equal(cmdlet.Metadata.Count, requestParameters.Metadata.Count);
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[0].Name], requestParameters.Metadata[0].Value);
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[1].Name], requestParameters.Metadata[1].Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System;
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
Expand Down Expand Up @@ -65,5 +66,78 @@ public void SetBatchJobScheduleParametersTest()
// Verify that no exceptions occur
cmdlet.ExecuteCmdlet();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SetBatchJobScheduleParametersGetPassedToRequestTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

cmdlet.JobSchedule = new PSCloudJobSchedule(BatchTestHelpers.CreateFakeBoundJobSchedule(context));

// Make changes to the job schedule
PSJobSpecification jobSpec = new PSJobSpecification()
{
DisplayName = "job display name",
CommonEnvironmentSettings = new List<PSEnvironmentSetting>()
{
new PSEnvironmentSetting("common1", "val1"),
new PSEnvironmentSetting("common2", "val2")
},
JobManagerTask = new PSJobManagerTask("job manager", "cmd /c echo job manager"),
JobPreparationTask = new PSJobPreparationTask("cmd /c echo job prep"),
JobReleaseTask = new PSJobReleaseTask("cmd /c echo job release"),
PoolInformation = new PSPoolInformation()
{
PoolId = "myPool"
}
};
cmdlet.JobSchedule.JobSpecification = jobSpec;

PSSchedule schedule = new PSSchedule()
{
DoNotRunAfter = DateTime.Now.AddYears(1),
DoNotRunUntil = DateTime.Now.AddDays(1),
RecurrenceInterval = TimeSpan.FromDays(1),
StartWindow = TimeSpan.FromHours(1)
};
cmdlet.JobSchedule.Schedule = schedule;

cmdlet.JobSchedule.Metadata = new List<PSMetadataItem>()
{
new PSMetadataItem("metadata1", "value1")
};

// Store the request parameters
JobScheduleUpdateParameter requestParameters = null;
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
JobScheduleUpdateParameter,
JobScheduleUpdateOptions,
AzureOperationHeaderResponse<JobScheduleUpdateHeaders>>(requestAction: (r) =>
{
requestParameters = r.Parameters;
});
cmdlet.AdditionalBehaviors = new BatchClientBehavior[] { interceptor };
cmdlet.ExecuteCmdlet();

// Verify that the request parameters contain the updated properties
Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count);
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name);
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value);
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name);
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value);
Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id);
Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine);
Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine);
Assert.Equal(jobSpec.PoolInformation.PoolId, requestParameters.JobSpecification.PoolInfo.PoolId);
Assert.Equal(schedule.DoNotRunAfter, requestParameters.Schedule.DoNotRunAfter);
Assert.Equal(schedule.DoNotRunUntil, requestParameters.Schedule.DoNotRunUntil);
Assert.Equal(schedule.RecurrenceInterval, requestParameters.Schedule.RecurrenceInterval);
Assert.Equal(schedule.StartWindow, requestParameters.Schedule.StartWindow);
Assert.Equal(cmdlet.JobSchedule.Metadata.Count, requestParameters.Metadata.Count);
Assert.Equal(cmdlet.JobSchedule.Metadata[0].Name, requestParameters.Metadata[0].Name);
Assert.Equal(cmdlet.JobSchedule.Metadata[0].Value, requestParameters.Metadata[0].Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,43 @@ public void ListJobsMaxCountTest()
Assert.Equal(idsOfConstructedJobs.Length, pipeline.Count);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchJobsUnderScheduleTest()
{
// Setup cmdlet to list jobs without filters.
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.JobScheduleId = "jobSchedule";

string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" };

// Build some CloudJobs instead of querying the service on a List Jobs from Job Schedule call
AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> response =
BatchTestHelpers.CreateJobListFromJobScheduleResponse(idsOfConstructedJobs);
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.JobListFromJobScheduleOptions,
AzureOperationResponse<IPage<ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders>>(response);
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Setup the cmdlet to write pipeline output to a list that can be examined later
List<PSCloudJob> pipeline = new List<PSCloudJob>();
commandRuntimeMock.Setup(r =>
r.WriteObject(It.IsAny<PSCloudJob>()))
.Callback<object>(j => pipeline.Add((PSCloudJob)j));

cmdlet.ExecuteCmdlet();

// Verify that the cmdlet wrote the constructed jobs to the pipeline
Assert.Equal(3, pipeline.Count);
int jobCount = 0;
foreach (PSCloudJob j in pipeline)
{
Assert.True(idsOfConstructedJobs.Contains(j.Id));
jobCount++;
}
Assert.Equal(idsOfConstructedJobs.Length, jobCount);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,61 @@ public void NewBatchJobParametersTest()
cmdlet.ExecuteCmdlet();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewBatchJobParametersGetPassedToRequestTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

cmdlet.Id = "testJob";
cmdlet.DisplayName = "display name";
cmdlet.CommonEnvironmentSettings = new Dictionary<string, string>();
cmdlet.CommonEnvironmentSettings.Add("commonEnv1", "value1");
cmdlet.Constraints = new PSJobConstraints(TimeSpan.FromHours(1), 5);
cmdlet.JobManagerTask = new PSJobManagerTask("job manager", "cmd /c echo job manager");
cmdlet.JobPreparationTask = new PSJobPreparationTask("cmd /c echo job prep");
cmdlet.JobReleaseTask = new PSJobReleaseTask("cmd /c echo job release");
cmdlet.PoolInformation = new PSPoolInformation()
{
PoolId = "myPool"
};
cmdlet.Priority = 2;
cmdlet.Metadata = new Dictionary<string, string>();
cmdlet.Metadata.Add("meta1", "value1");
cmdlet.Metadata.Add("meta2", "value2");
cmdlet.UsesTaskDependencies = true;

JobAddParameter requestParameters = null;

// Store the request parameters
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
JobAddParameter,
JobAddOptions,
AzureOperationHeaderResponse<JobAddHeaders>>(requestAction: (r) =>
{
requestParameters = r.Parameters;
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
cmdlet.ExecuteCmdlet();

// Verify the request parameters match the cmdlet parameters
Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
Assert.Equal(cmdlet.CommonEnvironmentSettings.Count, requestParameters.CommonEnvironmentSettings.Count);
Assert.Equal(cmdlet.CommonEnvironmentSettings[requestParameters.CommonEnvironmentSettings[0].Name], requestParameters.CommonEnvironmentSettings[0].Value);
Assert.Equal(cmdlet.Constraints.MaxTaskRetryCount, requestParameters.Constraints.MaxTaskRetryCount);
Assert.Equal(cmdlet.Constraints.MaxWallClockTime, requestParameters.Constraints.MaxWallClockTime);
Assert.Equal(cmdlet.JobManagerTask.Id, requestParameters.JobManagerTask.Id);
Assert.Equal(cmdlet.JobPreparationTask.CommandLine, requestParameters.JobPreparationTask.CommandLine);
Assert.Equal(cmdlet.JobReleaseTask.CommandLine, requestParameters.JobReleaseTask.CommandLine);
Assert.Equal(cmdlet.PoolInformation.PoolId, requestParameters.PoolInfo.PoolId);
Assert.Equal(cmdlet.Priority, requestParameters.Priority);
Assert.Equal(cmdlet.Metadata.Count, requestParameters.Metadata.Count);
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[0].Name], requestParameters.Metadata[0].Value);
Assert.Equal(cmdlet.Metadata[requestParameters.Metadata[1].Name], requestParameters.Metadata[1].Value);
Assert.Equal(cmdlet.UsesTaskDependencies, requestParameters.UsesTaskDependencies);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ApplicationPackageReferencesAreSentToService()
Expand Down
Loading