Skip to content

Commit 98c15b5

Browse files
committed
Merge pull request #205 from Azure/dev
.
2 parents dd76316 + 12cafe7 commit 98c15b5

26 files changed

+12768
-14
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@
180180
<Compile Include="Certificates\NewBatchCertificateCommandTests.cs" />
181181
<Compile Include="Certificates\RemoveBatchCertificateCommandTests.cs" />
182182
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
183+
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
183184
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
184185
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
185186
<Compile Include="ComputeNodeUsers\SetBatchComputeNoderUserCommandTests.cs" />
186187
<Compile Include="Files\GetBatchRemoteDesktopProtocolFileCommandTests.cs" />
187188
<Compile Include="Files\GetBatchNodeFileCommandTests.cs" />
188189
<Compile Include="Files\GetBatchNodeFileContentCommandTests.cs" />
190+
<Compile Include="Files\RemoveBatchNodeFileCommandTests.cs" />
189191
<Compile Include="JobSchedules\DisableBatchJobScheduleCommandTests.cs" />
190192
<Compile Include="JobSchedules\EnableBatchJobScheduleCommandTests.cs" />
191193
<Compile Include="JobSchedules\SetBatchJobScheduleCommandTests.cs" />
@@ -363,6 +365,15 @@
363365
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestReimageComputeNodePipeline.json">
364366
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
365367
</None>
368+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveComputeNodeById.json">
369+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
370+
</None>
371+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveComputeNodePipeline.json">
372+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
373+
</None>
374+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveMultipleComputeNodes.json">
375+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
376+
</None>
366377
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeUserTests\TestCreateComputeNodeUser.json">
367378
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
368379
</None>
@@ -375,6 +386,18 @@
375386
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeUserTests\TestUpdateComputeNodeUser.json">
376387
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
377388
</None>
389+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByComputeNodeByName.json">
390+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
391+
</None>
392+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByComputeNodeByPipeline.json">
393+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
394+
</None>
395+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByTaskByName.json">
396+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
397+
</None>
398+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByTaskByPipeline.json">
399+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
400+
</None>
378401
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetNodeFileByComputeNodeByName.json">
379402
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
380403
</None>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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.Common;
18+
using Microsoft.Azure.Batch.Protocol;
19+
using Microsoft.Azure.Batch.Protocol.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 RemoveBatchComputeNodeCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
31+
{
32+
private RemoveBatchComputeNodeCommand cmdlet;
33+
private Mock<BatchClient> batchClientMock;
34+
private Mock<ICommandRuntime> commandRuntimeMock;
35+
36+
public RemoveBatchComputeNodeCommandTests()
37+
{
38+
batchClientMock = new Mock<BatchClient>();
39+
commandRuntimeMock = new Mock<ICommandRuntime>();
40+
cmdlet = new RemoveBatchComputeNodeCommand()
41+
{
42+
CommandRuntime = commandRuntimeMock.Object,
43+
BatchClient = batchClientMock.Object,
44+
};
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void RemoveBatchComputeNodeParametersTest()
50+
{
51+
// Setup cmdlet to skip confirmation popup
52+
cmdlet.Force = true;
53+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
54+
55+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
56+
cmdlet.BatchContext = context;
57+
cmdlet.Ids = null;
58+
59+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
60+
61+
cmdlet.PoolId = "testPool";
62+
63+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
64+
65+
cmdlet.Ids = new string[] { "computeNode1" };
66+
67+
// Don't go to the service on a Remove ComputeNode call
68+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse>();
69+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
70+
71+
// Verify no exceptions when required parameter is set
72+
cmdlet.ExecuteCmdlet();
73+
}
74+
75+
[Fact]
76+
[Trait(Category.AcceptanceType, Category.CheckIn)]
77+
public void RemoveComputeNodeRequestTest()
78+
{
79+
// Setup cmdlet to skip confirmation popup
80+
cmdlet.Force = true;
81+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
82+
83+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
84+
cmdlet.BatchContext = context;
85+
86+
cmdlet.PoolId = "testPool";
87+
cmdlet.Ids = new string[] { "computeNode1", "computeNode2" };
88+
cmdlet.DeallocationOption = ComputeNodeDeallocationOption.Terminate;
89+
cmdlet.ResizeTimeout = TimeSpan.FromMinutes(8);
90+
91+
ComputeNodeDeallocationOption? requestDeallocationOption = null;
92+
TimeSpan? requestResizeTimeout = null;
93+
IList<string> requestComputeNodeIds = null;
94+
95+
// Don't go to the service on a Remove ComputeNode call
96+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
97+
{
98+
BatchRequest<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse> request =
99+
(BatchRequest<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse>)baseRequest;
100+
101+
request.ServiceRequestFunc = (cancellationToken) =>
102+
{
103+
// Grab the parameters from the outgoing request.
104+
requestDeallocationOption = request.TypedParameters.ComputeNodeDeallocationOption;
105+
requestResizeTimeout = request.TypedParameters.ResizeTimeout;
106+
requestComputeNodeIds = request.TypedParameters.ComputeNodeIds;
107+
108+
ComputeNodeRemoveResponse response = new ComputeNodeRemoveResponse();
109+
Task<ComputeNodeRemoveResponse> task = Task.FromResult(response);
110+
return task;
111+
};
112+
});
113+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
114+
115+
cmdlet.ExecuteCmdlet();
116+
117+
// Verify that the parameters were properly set on the outgoing request
118+
Assert.Equal(cmdlet.DeallocationOption, requestDeallocationOption);
119+
Assert.Equal(cmdlet.ResizeTimeout, requestResizeTimeout);
120+
Assert.Equal(cmdlet.Ids.Length, requestComputeNodeIds.Count);
121+
foreach (string id in cmdlet.Ids)
122+
{
123+
Assert.True(requestComputeNodeIds.Contains(id));
124+
}
125+
}
126+
}
127+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 System.IO;
17+
using Microsoft.Azure.Batch;
18+
using Microsoft.Azure.Batch.Protocol;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using Xunit;
24+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
25+
using Microsoft.Azure.Batch.Protocol.Models;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.Files
28+
{
29+
public class RemoveBatchNodeFileCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
30+
{
31+
private RemoveBatchNodeFileCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public RemoveBatchNodeFileCommandTests()
36+
{
37+
batchClientMock = new Mock<BatchClient>();
38+
commandRuntimeMock = new Mock<ICommandRuntime>();
39+
cmdlet = new RemoveBatchNodeFileCommand()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
BatchClient = batchClientMock.Object,
43+
};
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void RemoveBatchNodeFileParametersTest()
49+
{
50+
// Setup cmdlet to skip confirmation popup
51+
cmdlet.Force = true;
52+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
53+
54+
// Setup cmdlet without required parameters
55+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
56+
cmdlet.BatchContext = context;
57+
cmdlet.JobId = null;
58+
cmdlet.TaskId = null;
59+
cmdlet.Name = null;
60+
cmdlet.InputObject = null;
61+
62+
// Don't go to the service on a Delete NodeFile call
63+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<NodeFileDeleteParameters, NodeFileDeleteResponse>();
64+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
65+
66+
Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());
67+
68+
// Fill required task details
69+
cmdlet.JobId = "job-1";
70+
cmdlet.TaskId = "task";
71+
cmdlet.Name = "stdout.txt";
72+
73+
// Verify no exceptions occur
74+
cmdlet.ExecuteCmdlet();
75+
76+
// Setup compute node parameters
77+
cmdlet.JobId = null;
78+
cmdlet.TaskId = null;
79+
cmdlet.PoolId = "testPool";
80+
cmdlet.ComputeNodeId = "computeNode-1";
81+
82+
// Verify no exceptions occur
83+
cmdlet.ExecuteCmdlet();
84+
}
85+
}
86+
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/Common.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15+
<#
16+
.SYNOPSIS
17+
Sleeps but only during recording.
18+
#>
19+
function Start-TestSleep($milliseconds)
20+
{
21+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
22+
{
23+
Start-Sleep -Milliseconds $milliseconds
24+
}
25+
}
26+
1527
<#
1628
.SYNOPSIS
1729
Gets a ScenarioTestContext for the specified account

0 commit comments

Comments
 (0)