Skip to content

Commit 5bdf417

Browse files
author
jasper-schneider
committed
WORK:3478243 Add/Remove Pool
1 parent ebbfff6 commit 5bdf417

22 files changed

+9959
-1266
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@
158158
<Compile Include="Jobs\RemoveBatchJobCommandTests.cs" />
159159
<Compile Include="Models\BatchAccountContextTest.cs" />
160160
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
161+
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
162+
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
161163
<Compile Include="Properties\AssemblyInfo.cs" />
162164
<Compile Include="ScenarioTests\BatchAccountTests.cs" />
163165
<Compile Include="ScenarioTests\BatchController.cs" />
@@ -241,6 +243,12 @@
241243
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestListJobsWithMaxCount.json">
242244
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
243245
</None>
246+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDeletePool.json">
247+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
248+
</None>
249+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDeletePoolPipeline.json">
250+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
251+
</None>
244252
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestGetPoolByName.json">
245253
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
246254
</None>
@@ -253,6 +261,9 @@
253261
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestListPoolsWithMaxCount.json">
254262
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
255263
</None>
264+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestNewPool.json">
265+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
266+
</None>
256267
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestCreateTask.json">
257268
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
258269
</None>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Entities;
19+
using Microsoft.Azure.Commands.Batch.Models;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Moq;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using System.Threading.Tasks;
25+
using Xunit;
26+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
27+
28+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
29+
{
30+
public class NewBatchPoolCommandTests
31+
{
32+
private NewBatchPoolCommand cmdlet;
33+
private Mock<BatchClient> batchClientMock;
34+
private Mock<ICommandRuntime> commandRuntimeMock;
35+
36+
public NewBatchPoolCommandTests()
37+
{
38+
batchClientMock = new Mock<BatchClient>();
39+
commandRuntimeMock = new Mock<ICommandRuntime>();
40+
cmdlet = new NewBatchPoolCommand()
41+
{
42+
CommandRuntime = commandRuntimeMock.Object,
43+
BatchClient = batchClientMock.Object,
44+
};
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void NewBatchPoolParametersTest()
50+
{
51+
// Setup cmdlet without the required parameters
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
55+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
56+
57+
cmdlet.Name = "testPool";
58+
59+
// Don't go to the service on an AddPool call
60+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
61+
{
62+
if (request is AddPoolRequest)
63+
{
64+
AddPoolResponse response = new AddPoolResponse();
65+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
66+
return task;
67+
}
68+
return null;
69+
});
70+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
71+
72+
// Verify no exceptions when required parameters are set
73+
cmdlet.ExecuteCmdlet();
74+
}
75+
}
76+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Entities;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using System.Threading.Tasks;
24+
using Xunit;
25+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
28+
{
29+
public class RemoveBatchPoolCommandTests
30+
{
31+
private RemoveBatchPoolCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public RemoveBatchPoolCommandTests()
36+
{
37+
batchClientMock = new Mock<BatchClient>();
38+
commandRuntimeMock = new Mock<ICommandRuntime>();
39+
cmdlet = new RemoveBatchPoolCommand()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
BatchClient = batchClientMock.Object,
43+
};
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void RemoveBatchPoolParametersTest()
49+
{
50+
// Setup cmdlet without the required parameters
51+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
52+
cmdlet.BatchContext = context;
53+
54+
// Setup cmdlet to skip confirmation popup
55+
cmdlet.Force = true;
56+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
57+
58+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
59+
60+
cmdlet.Name = "testPool";
61+
62+
// Don't go to the service on a DeletePool call
63+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
64+
{
65+
if (request is DeletePoolRequest)
66+
{
67+
DeletePoolResponse response = new DeletePoolResponse();
68+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
69+
return task;
70+
}
71+
return null;
72+
});
73+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
74+
75+
// Verify no exceptions when required parameters are set
76+
cmdlet.ExecuteCmdlet();
77+
}
78+
}
79+
}

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/PoolTests.cs

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
2424
{
2525
public class PoolTests
2626
{
27+
[Fact]
28+
[Trait(Category.AcceptanceType, Category.CheckIn)]
29+
public void TestNewPool()
30+
{
31+
BatchController controller = BatchController.NewInstance;
32+
string resourceGroupName = "test-new-pool";
33+
string accountName = "testnewpool";
34+
string location = "eastus";
35+
BatchAccountContext context = null;
36+
controller.RunPsTestWorkflow(
37+
() => { return new string[] { string.Format("Test-NewPool '{0}'", accountName) }; },
38+
() =>
39+
{
40+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
41+
},
42+
() =>
43+
{
44+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
45+
},
46+
TestUtilities.GetCallingClass(),
47+
TestUtilities.GetCurrentMethodName());
48+
}
49+
2750
[Fact]
2851
[Trait(Category.AcceptanceType, Category.CheckIn)]
2952
public void TestGetPoolByName()
@@ -39,11 +62,11 @@ public void TestGetPoolByName()
3962
() =>
4063
{
4164
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
42-
ScenarioTestHelpers.CreateTestPool(context, poolName);
65+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName);
4366
},
4467
() =>
4568
{
46-
ScenarioTestHelpers.DeletePool(context, poolName);
69+
ScenarioTestHelpers.DeletePool(controller, context, poolName);
4770
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
4871
},
4972
TestUtilities.GetCallingClass(),
@@ -69,15 +92,15 @@ public void TestListPoolsByFilter()
6992
() =>
7093
{
7194
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
72-
ScenarioTestHelpers.CreateTestPool(context, poolName1);
73-
ScenarioTestHelpers.CreateTestPool(context, poolName2);
74-
ScenarioTestHelpers.CreateTestPool(context, poolName3);
95+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName1);
96+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName2);
97+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName3);
7598
},
7699
() =>
77100
{
78-
ScenarioTestHelpers.DeletePool(context, poolName1);
79-
ScenarioTestHelpers.DeletePool(context, poolName2);
80-
ScenarioTestHelpers.DeletePool(context, poolName3);
101+
ScenarioTestHelpers.DeletePool(controller, context, poolName1);
102+
ScenarioTestHelpers.DeletePool(controller, context, poolName2);
103+
ScenarioTestHelpers.DeletePool(controller, context, poolName3);
81104
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
82105
},
83106
TestUtilities.GetCallingClass(),
@@ -102,15 +125,15 @@ public void TestListPoolsWithMaxCount()
102125
() =>
103126
{
104127
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
105-
ScenarioTestHelpers.CreateTestPool(context, poolName1);
106-
ScenarioTestHelpers.CreateTestPool(context, poolName2);
107-
ScenarioTestHelpers.CreateTestPool(context, poolName3);
128+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName1);
129+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName2);
130+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName3);
108131
},
109132
() =>
110133
{
111-
ScenarioTestHelpers.DeletePool(context, poolName1);
112-
ScenarioTestHelpers.DeletePool(context, poolName2);
113-
ScenarioTestHelpers.DeletePool(context, poolName3);
134+
ScenarioTestHelpers.DeletePool(controller, context, poolName1);
135+
ScenarioTestHelpers.DeletePool(controller, context, poolName2);
136+
ScenarioTestHelpers.DeletePool(controller, context, poolName3);
114137
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
115138
},
116139
TestUtilities.GetCallingClass(),
@@ -135,21 +158,72 @@ public void TestListAllPools()
135158
() =>
136159
{
137160
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
138-
ScenarioTestHelpers.CreateTestPool(context, poolName1);
139-
ScenarioTestHelpers.CreateTestPool(context, poolName2);
140-
ScenarioTestHelpers.CreateTestPool(context, poolName3);
161+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName1);
162+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName2);
163+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName3);
164+
},
165+
() =>
166+
{
167+
ScenarioTestHelpers.DeletePool(controller, context, poolName1);
168+
ScenarioTestHelpers.DeletePool(controller, context, poolName2);
169+
ScenarioTestHelpers.DeletePool(controller, context, poolName3);
170+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
171+
},
172+
TestUtilities.GetCallingClass(),
173+
TestUtilities.GetCurrentMethodName());
174+
}
175+
176+
[Fact]
177+
[Trait(Category.AcceptanceType, Category.CheckIn)]
178+
public void TestDeletePool()
179+
{
180+
BatchController controller = BatchController.NewInstance;
181+
string resourceGroupName = "test-delete-pool";
182+
string accountName = "testdeletepool";
183+
string location = "eastus";
184+
string poolName = "testPool";
185+
186+
BatchAccountContext context = null;
187+
controller.RunPsTestWorkflow(
188+
() => { return new string[] { string.Format("Test-DeletePool '{0}' '{1}' '0'", accountName, poolName) }; },
189+
() =>
190+
{
191+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
192+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName);
141193
},
142194
() =>
143195
{
144-
ScenarioTestHelpers.DeletePool(context, poolName1);
145-
ScenarioTestHelpers.DeletePool(context, poolName2);
146-
ScenarioTestHelpers.DeletePool(context, poolName3);
147196
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
148197
},
149198
TestUtilities.GetCallingClass(),
150199
TestUtilities.GetCurrentMethodName());
151200
}
152201

202+
[Fact]
203+
[Trait(Category.AcceptanceType, Category.CheckIn)]
204+
public void TestDeletePoolPipeline()
205+
{
206+
BatchController controller = BatchController.NewInstance;
207+
string resourceGroupName = "test-delete-pool";
208+
string accountName = "testdeletepool";
209+
string location = "eastus";
210+
string poolName = "testPool";
211+
212+
BatchAccountContext context = null;
213+
controller.RunPsTestWorkflow(
214+
() => { return new string[] { string.Format("Test-DeletePool '{0}' '{1}' '1'", accountName, poolName) }; },
215+
() =>
216+
{
217+
context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
218+
ScenarioTestHelpers.CreateTestPool(controller, context, poolName);
219+
},
220+
() =>
221+
{
222+
ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
223+
},
224+
TestUtilities.GetCallingClass(),
225+
TestUtilities.GetCurrentMethodName());
226+
}
153227
}
154228

155229
// Cmdlets that use the HTTP Recorder interceptor for use with scenario tests
@@ -162,4 +236,24 @@ public override void ExecuteCmdlet()
162236
base.ExecuteCmdlet();
163237
}
164238
}
239+
240+
[Cmdlet(VerbsCommon.New, "AzureBatchPool_ST", DefaultParameterSetName = TargetDedicatedParameterSet)]
241+
public class NewBatchPoolScenarioTestCommand : NewBatchPoolCommand
242+
{
243+
public override void ExecuteCmdlet()
244+
{
245+
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
246+
base.ExecuteCmdlet();
247+
}
248+
}
249+
250+
[Cmdlet(VerbsCommon.Remove, "AzureBatchPool_ST")]
251+
public class RemoveBatchPoolScenarioTestCommand : RemoveBatchPoolCommand
252+
{
253+
public override void ExecuteCmdlet()
254+
{
255+
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
256+
base.ExecuteCmdlet();
257+
}
258+
}
165259
}

0 commit comments

Comments
 (0)