Skip to content

Commit d689b14

Browse files
author
jasper-schneider
committed
Get Job scenario tests
1 parent 910c17b commit d689b14

File tree

10 files changed

+8167
-13
lines changed

10 files changed

+8167
-13
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
<Compile Include="Properties\AssemblyInfo.cs" />
158158
<Compile Include="ScenarioTests\BatchAccountTests.cs" />
159159
<Compile Include="ScenarioTests\BatchController.cs" />
160+
<Compile Include="ScenarioTests\JobTests.cs" />
160161
<Compile Include="ScenarioTests\PoolTests.cs" />
161162
<Compile Include="ScenarioTests\ScenarioTestHelpers.cs" />
162163
<Compile Include="ScenarioTests\WorkItemTests.cs" />
@@ -174,6 +175,9 @@
174175
<None Include="ScenarioTests\Common.ps1">
175176
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
176177
</None>
178+
<None Include="ScenarioTests\JobTests.ps1">
179+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
180+
</None>
177181
<None Include="ScenarioTests\PoolTests.ps1">
178182
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
179183
</None>
@@ -201,6 +205,24 @@
201205
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests\TestUpdatesExistingBatchAccount.json">
202206
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
203207
</None>
208+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestGetJobByName.json">
209+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
210+
</None>
211+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestGetJobRequiredParameters.json">
212+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
213+
</None>
214+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestListAllJobs.json">
215+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
216+
</None>
217+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestListJobPipeline.json">
218+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
219+
</None>
220+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestListJobsByFilter.json">
221+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
222+
</None>
223+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestListJobsWithMaxCount.json">
224+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
225+
</None>
204226
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestGetPoolByName.json">
205227
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
206228
</None>
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using Microsoft.Azure.Test;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using System.Collections.Generic;
21+
using System.Management.Automation;
22+
using Xunit;
23+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
24+
25+
namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
26+
{
27+
public class JobTests
28+
{
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestGetJobRequiredParameters()
32+
{
33+
BatchController controller = BatchController.NewInstance;
34+
string resourceGroupName = "test-get-job-params";
35+
string accountName = "testgetjobparams";
36+
string location = "eastus";
37+
BatchAccountContext context = null;
38+
controller.RunPsTestWorkflow(
39+
() => { return new string[] { string.Format("Test-GetJobRequiredParameters '{0}'", accountName) }; },
40+
() =>
41+
{
42+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
43+
},
44+
() =>
45+
{
46+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
47+
},
48+
TestUtilities.GetCallingClass(),
49+
TestUtilities.GetCurrentMethodName());
50+
}
51+
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
public void TestGetJobByName()
55+
{
56+
BatchController controller = BatchController.NewInstance;
57+
string resourceGroupName = "test-get-job";
58+
string accountName = "testgetjob";
59+
string location = "eastus";
60+
string workItemName = "testName";
61+
string jobName = null;
62+
BatchAccountContext context = null;
63+
controller.RunPsTestWorkflow(
64+
() => { return new string[] { string.Format("Test-GetJobByName '{0}' '{1}' '{2}'", accountName, workItemName, jobName) }; },
65+
() =>
66+
{
67+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
68+
ScenarioTestHelpers.CreateTestWorkItem(context, workItemName);
69+
jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName);
70+
},
71+
() =>
72+
{
73+
ScenarioTestHelpers.DeleteWorkItem(context, workItemName);
74+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
75+
},
76+
TestUtilities.GetCallingClass(),
77+
TestUtilities.GetCurrentMethodName());
78+
}
79+
80+
[Fact]
81+
[Trait(Category.AcceptanceType, Category.CheckIn)]
82+
public void TestListJobsByFilter()
83+
{
84+
BatchController controller = BatchController.NewInstance;
85+
string resourceGroupName = "test-list-job-filter";
86+
string accountName = "testlistjobfilter";
87+
string location = "eastus";
88+
string workItemName = "testWorkItem";
89+
string state = "active";
90+
int matches = 1;
91+
BatchAccountContext context = null;
92+
controller.RunPsTestWorkflow(
93+
() => { return new string[] { string.Format("Test-ListJobsByFilter '{0}' '{1}' '{2}' '{3}'", accountName, workItemName, state, matches) }; },
94+
() =>
95+
{
96+
TimeSpan recurrence = TimeSpan.FromMinutes(1);
97+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
98+
ScenarioTestHelpers.CreateTestWorkItem(context, workItemName, recurrence);
99+
string jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName);
100+
ScenarioTestHelpers.TerminateJob(context, workItemName, jobName);
101+
ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName, jobName);
102+
},
103+
() =>
104+
{
105+
ScenarioTestHelpers.DeleteWorkItem(context, workItemName);
106+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
107+
},
108+
TestUtilities.GetCallingClass(),
109+
TestUtilities.GetCurrentMethodName());
110+
}
111+
112+
[Fact]
113+
[Trait(Category.AcceptanceType, Category.CheckIn)]
114+
public void TestListJobsWithMaxCount()
115+
{
116+
BatchController controller = BatchController.NewInstance;
117+
string resourceGroupName = "test-list-job-maxcount";
118+
string accountName = "testlistjobmaxcount";
119+
string location = "eastus";
120+
string workItemName = "testWorkItem";
121+
int maxCount = 1;
122+
BatchAccountContext context = null;
123+
controller.RunPsTestWorkflow(
124+
() => { return new string[] { string.Format("Test-ListJobsWithMaxCount '{0}' '{1}' '{2}'", accountName, workItemName, maxCount) }; },
125+
() =>
126+
{
127+
TimeSpan recurrence = TimeSpan.FromMinutes(1);
128+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
129+
ScenarioTestHelpers.CreateTestWorkItem(context, workItemName, recurrence);
130+
string jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName);
131+
ScenarioTestHelpers.TerminateJob(context, workItemName, jobName);
132+
ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName, jobName);
133+
},
134+
() =>
135+
{
136+
ScenarioTestHelpers.DeleteWorkItem(context, workItemName);
137+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
138+
},
139+
TestUtilities.GetCallingClass(),
140+
TestUtilities.GetCurrentMethodName());
141+
}
142+
143+
[Fact]
144+
[Trait(Category.AcceptanceType, Category.CheckIn)]
145+
public void TestListAllJobs()
146+
{
147+
BatchController controller = BatchController.NewInstance;
148+
string resourceGroupName = "test-list-job";
149+
string accountName = "testlistjob";
150+
string location = "eastus";
151+
string workItemName = "testWorkItem";
152+
int count = 2;
153+
BatchAccountContext context = null;
154+
controller.RunPsTestWorkflow(
155+
() => { return new string[] { string.Format("Test-ListAllJobs '{0}' '{1}' '{2}'", accountName, workItemName, count) }; },
156+
() =>
157+
{
158+
TimeSpan recurrence = TimeSpan.FromMinutes(1);
159+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
160+
ScenarioTestHelpers.CreateTestWorkItem(context, workItemName, recurrence);
161+
string jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName);
162+
ScenarioTestHelpers.TerminateJob(context, workItemName, jobName);
163+
ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName, jobName);
164+
},
165+
() =>
166+
{
167+
ScenarioTestHelpers.DeleteWorkItem(context, workItemName);
168+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
169+
},
170+
TestUtilities.GetCallingClass(),
171+
TestUtilities.GetCurrentMethodName());
172+
}
173+
174+
[Fact]
175+
[Trait(Category.AcceptanceType, Category.CheckIn)]
176+
public void TestListJobPipeline()
177+
{
178+
BatchController controller = BatchController.NewInstance;
179+
string resourceGroupName = "test-list-job-pipe";
180+
string accountName = "testlistjobpipe";
181+
string location = "eastus";
182+
string workItemName = "testWorkItem";
183+
string jobName = null;
184+
185+
BatchAccountContext context = null;
186+
controller.RunPsTestWorkflow(
187+
() => { return new string[] { string.Format("Test-ListJobPipeline '{0}' '{1}' '{2}'", accountName, workItemName, jobName) }; },
188+
() =>
189+
{
190+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
191+
ScenarioTestHelpers.CreateTestWorkItem(context, workItemName);
192+
jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName);
193+
},
194+
() =>
195+
{
196+
ScenarioTestHelpers.DeleteWorkItem(context, workItemName);
197+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
198+
},
199+
TestUtilities.GetCallingClass(),
200+
TestUtilities.GetCurrentMethodName());
201+
}
202+
203+
}
204+
205+
// Cmdlets that use the HTTP Recorder interceptor for use with scenario tests
206+
[Cmdlet(VerbsCommon.Get, "AzureBatchJob_ST", DefaultParameterSetName = Constants.ODataFilterParameterSet)]
207+
public class GetBatchJobScenarioTestCommand : GetBatchJobCommand
208+
{
209+
public override void ExecuteCmdlet()
210+
{
211+
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
212+
base.ExecuteCmdlet();
213+
}
214+
}
215+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests that calling Get-AzureBatchJob without required parameters throws error
18+
#>
19+
function Test-GetJobRequiredParameters
20+
{
21+
param([string]$accountName)
22+
23+
$context = Get-AzureBatchAccountKeys -Name $accountName
24+
Assert-Throws { Get-AzureBatchJob_ST -BatchContext $context }
25+
}
26+
27+
<#
28+
.SYNOPSIS
29+
Tests querying for a Batch Job by name
30+
#>
31+
function Test-GetJobByName
32+
{
33+
param([string]$accountName, [string]$wiName, [string]$jobName)
34+
35+
$context = Get-AzureBatchAccountKeys -Name $accountName
36+
$job = Get-AzureBatchJob_ST -WorkItemName $wiName -Name $jobName -BatchContext $context
37+
38+
Assert-AreEqual $jobName $job.Name
39+
40+
# Verify positional parameters also work
41+
$job = Get-AzureBatchJob_ST $wiName $jobName -BatchContext $context
42+
43+
Assert-AreEqual $jobName $job.Name
44+
}
45+
46+
<#
47+
.SYNOPSIS
48+
Tests querying for Batch Jobs using a filter
49+
#>
50+
function Test-ListJobsByFilter
51+
{
52+
param([string]$accountName, [string]$workItemName, [string]$state, [string]$matches)
53+
54+
$context = Get-AzureBatchAccountKeys -Name $accountName
55+
$filter = "state eq '" + "$state" + "'"
56+
57+
$jobs = Get-AzureBatchJob_ST -WorkItemName $workItemName -Filter $filter -BatchContext $context
58+
59+
Assert-AreEqual $matches $jobs.Length
60+
foreach($job in $jobs)
61+
{
62+
Assert-AreEqual $state $job.State.ToString().ToLower()
63+
}
64+
65+
# Verify parent object parameter set also works
66+
$workItem = Get-AzureBatchWorkItem_ST $workItemName -BatchContext $context
67+
$jobs = Get-AzureBatchJob_ST -WorkItem $workItem -Filter $filter -BatchContext $context
68+
69+
Assert-AreEqual $matches $jobs.Length
70+
foreach($job in $jobs)
71+
{
72+
Assert-AreEqual $state $job.State.ToString().ToLower()
73+
}
74+
}
75+
76+
<#
77+
.SYNOPSIS
78+
Tests querying for Batch Jobs and supplying a max count
79+
#>
80+
function Test-ListJobsWithMaxCount
81+
{
82+
param([string]$accountName, [string]$workItemName, [string]$maxCount)
83+
84+
$context = Get-AzureBatchAccountKeys -Name $accountName
85+
$jobs = Get-AzureBatchJob_ST -WorkItemName $workItemName -MaxCount $maxCount -BatchContext $context
86+
87+
Assert-AreEqual $maxCount $jobs.Length
88+
89+
# Verify parent object parameter set also works
90+
$workItem = Get-AzureBatchWorkItem_ST $workItemName -BatchContext $context
91+
$jobs = Get-AzureBatchJob_ST -WorkItem $workItem -MaxCount $maxCount -BatchContext $context
92+
93+
Assert-AreEqual $maxCount $jobs.Length
94+
}
95+
96+
<#
97+
.SYNOPSIS
98+
Tests querying for all Jobs under a WorkItem
99+
#>
100+
function Test-ListAllJobs
101+
{
102+
param([string]$accountName, [string]$workItemName, [string]$count)
103+
104+
$context = Get-AzureBatchAccountKeys -Name $accountName
105+
$jobs = Get-AzureBatchJob_ST -WorkItemName $workItemName -BatchContext $context
106+
107+
Assert-AreEqual $count $jobs.Length
108+
109+
# Verify parent object parameter set also works
110+
$workItem = Get-AzureBatchWorkItem_ST $workItemName -BatchContext $context
111+
$jobs = Get-AzureBatchJob_ST -WorkItem $workItem -BatchContext $context
112+
113+
Assert-AreEqual $count $jobs.Length
114+
}
115+
116+
<#
117+
.SYNOPSIS
118+
Tests piping Get-AzureBatchWorkItem into Get-AzureBatchJob
119+
#>
120+
function Test-ListJobPipeline
121+
{
122+
param([string]$accountName, [string]$workItemName, [string]$jobName)
123+
124+
$context = Get-AzureBatchAccountKeys -Name $accountName
125+
$job = Get-AzureBatchWorkItem_ST -Name $workItemName -BatchContext $context | Get-AzureBatchJob_ST -BatchContext $context
126+
127+
Assert-AreEqual $jobName $job.Name
128+
}

0 commit comments

Comments
 (0)