Skip to content

Commit cad197e

Browse files
committed
add tests for managed app, app type, app type version, service
1 parent 923fcdb commit cad197e

File tree

8 files changed

+24199
-1
lines changed

8 files changed

+24199
-1
lines changed

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/Common.ps1

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,37 @@ function WaitForClusterReadyState($clusterName, $resourceGroupName, $timeoutInSe
187187
return $false
188188
}
189189

190+
function WaitForManagedClusterReadyStateIfRecord($clusterName, $resourceGroupName)
191+
{
192+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
193+
{
194+
# Wait for Ready cluster state before updating otherwise update is going to fail
195+
if (-not (WaitForManagedClusterReadyState $clusterName $resourceGroupName))
196+
{
197+
Assert-True $false 'Cluster is not in Ready state. Can not continue with test.'
198+
}
199+
}
200+
}
201+
202+
function WaitForManagedClusterReadyState($clusterName, $resourceGroupName, $timeoutInSeconds = 1200)
203+
{
204+
$timeoutTime = (Get-Date).AddSeconds($timeoutInSeconds)
205+
while (-not $clusterReady -and (Get-Date) -lt $timeoutTime) {
206+
$cluster = (Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName)[0]
207+
if ($cluster.ClusterState -eq "Ready")
208+
{
209+
return $true
210+
break
211+
}
212+
213+
Write-Host "Cluster state: $($cluster.ClusterState). Waiting for Ready state before continuing."
214+
Start-Sleep -Seconds 15
215+
}
216+
217+
Write-Error "WaitForClusterReadyState timed out"
218+
return $false
219+
}
220+
190221
function WaitForAllJob($timeoutInSeconds = 1200)
191222
{
192223
$timeoutTime = (Get-Date).AddSeconds($timeoutInSeconds)
@@ -214,6 +245,53 @@ function WaitForAllJob($timeoutInSeconds = 1200)
214245
return $false
215246
}
216247

248+
<#
249+
.SYNOPSIS
250+
Asserts if two hashtables with simple key and value types are equal
251+
#>
252+
function Assert-HashtableEqual($h1, $h2)
253+
{
254+
if($h1.count -ne $h2.count)
255+
{
256+
throw "Hashtable size not equal. Hashtable1: " + $h1.count + " Hashtable2: " + $h2.count
257+
}
258+
259+
foreach($key in $h1.Keys)
260+
{
261+
if($h1[$key] -ne $h2[$key])
262+
{
263+
throw "Tag content not equal. Key:$key Tags1:" + $h1[$key] + " Tags2:" + $h2[$key]
264+
}
265+
}
266+
}
267+
268+
###################
269+
#
270+
# Verify that the actual string ends with the expected suffix
271+
#
272+
# param [string] $expectedSuffix : The expected suffix
273+
# param [string] $actual : The actual string
274+
# param [string] $message : The message to return if the actual string does not end with the suffix
275+
####################
276+
function Assert-EndsWith
277+
{
278+
param([string] $expectedSuffix, [string] $actual, [string] $message)
279+
280+
Assert-NotNull $actual
281+
282+
if (!$message)
283+
{
284+
$message = "Assertion failed because actual '$actual' does not end with '$expectedSuffix'"
285+
}
286+
287+
if (-not $actual.EndsWith($expectedSuffix))
288+
{
289+
throw $message
290+
}
291+
292+
return $true
293+
}
294+
217295
# Application functions
218296

219297
function Get-AppTypeName
@@ -244,4 +322,41 @@ function Get-AppPackageV2
244322
function Get-ServiceTypeName
245323
{
246324
return "CalcServiceType"
325+
}
326+
327+
# Managed Application functions
328+
329+
function Get-ManagedAppTypeName
330+
{
331+
return "VotingType"
332+
}
333+
334+
function Get-ManagedAppTypeV1Name
335+
{
336+
return "1.0.0"
337+
}
338+
339+
function Get-ManagedAppTypeV2Name
340+
{
341+
return "2.0.0"
342+
}
343+
344+
function Get-ManagedAppPackageV1
345+
{
346+
return "https://sfmconeboxst.blob.core.windows.net/managed-application-deployment/Voting.sfpkg"
347+
}
348+
349+
function Get-ManagedAppPackageV2
350+
{
351+
return "https://sfmconeboxst.blob.core.windows.net/managed-application-deployment/Voting.2.0.0.sfpkg"
352+
}
353+
354+
function Get-ManagedStatelessServiceTypeName
355+
{
356+
return "VotingWebType"
357+
}
358+
359+
function Get-ManagedStatefulServiceTypeName
360+
{
361+
return "VotingDataType"
247362
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 Microsoft.Azure.Commands.ServiceFabric.Commands;
16+
using Microsoft.Azure.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests
23+
{
24+
public class ServiceFabricManagedClustersApplicationTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public ServiceFabricManagedClustersApplicationTests(ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
33+
ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
34+
ServiceFabricCmdletBase.RunningTest = true;
35+
}
36+
37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestManagedAppType()
40+
{
41+
TestController.NewInstance.RunPsTest(_logger, "Test-ManagedAppType");
42+
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
public void TestManagedAppTypeVersion()
47+
{
48+
TestController.NewInstance.RunPsTest(_logger, "Test-ManagedAppTypeVersion");
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void TestManagedApp()
54+
{
55+
TestController.NewInstance.RunPsTest(_logger, "Test-ManagedApp");
56+
}
57+
58+
[Fact]
59+
[Trait(Category.AcceptanceType, Category.CheckIn)]
60+
public void TestManagedService()
61+
{
62+
TestController.NewInstance.RunPsTest(_logger, "Test-ManagedService");
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)