Skip to content

Commit ad487d6

Browse files
committed
Fixed network watcher tests
1 parent b797ada commit ad487d6

File tree

2 files changed

+50
-39
lines changed

2 files changed

+50
-39
lines changed

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/NetworkWatcherAPITests.ps1

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ function Get-DeleteAndCreateTestNetworkWatcher($location, $nwName, $nwRgName, $t
142142
# Delete Network Watcher if existing nw
143143
if ($nw)
144144
{
145-
Remove-AzureRmNetworkWatcher -NetworkWatcher $nw
145+
$job = Remove-AzureRmNetworkWatcher -NetworkWatcher $nw -AsJob
146+
$job | Wait-Job
147+
$delete = $job | Receive-Job
146148
}
147149

148150
$nw = New-AzureRmNetworkWatcher -Name $nwName -ResourceGroupName $nwRgName -Location $location -Tag $tags
@@ -499,7 +501,7 @@ function Test-Troubleshoot
499501
# Setup
500502
$resourceGroupName = Get-ResourceGroupName
501503
$nwName = Get-ResourceName
502-
$location = "centraluseuap"
504+
$location = "westus"
503505
$resourceTypeParent = "Microsoft.Network/networkWatchers"
504506
$nwLocation = Get-ProviderLocation $resourceTypeParent
505507
$nwRgName = Get-ResourceGroupName
@@ -572,7 +574,7 @@ function Test-FlowLog
572574
$nwName = Get-ResourceName
573575
#Since Traffic Analytics is not available in all Azure regions, hardcoded locations are used
574576
#Once Traffic Analytics is available in all Azure regions, the below two location variables should be updated to Get-Location
575-
$location = "eastus2euap"
577+
$location = "westcentralus"
576578
$workspaceLocation = "eastus"
577579
$resourceTypeParent = "Microsoft.Network/networkWatchers"
578580
$nwLocation = Get-ProviderLocation $resourceTypeParent
@@ -723,18 +725,16 @@ function Test-ReachabilityReport
723725
# Setup
724726
$rgname = Get-ResourceGroupName
725727
$nwName = Get-ResourceName
726-
$rglocation = Get-ProviderLocation ResourceManagement
727728
$resourceTypeParent = "Microsoft.Network/networkWatchers"
728729
$location = "westus"
729730

730731
try
731732
{
732733
# Create the resource group
733-
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
734-
735-
# Create the Network Watcher
736-
$tags = @{"key1" = "value1"; "key2" = "value2"}
737-
$nw = Get-DeleteAndCreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $rgname -tags $tags
734+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "testval" }
735+
736+
# Get Network Watcher
737+
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $rgName
738738

739739
$job = Get-AzureRmNetworkWatcherReachabilityReport -NetworkWatcher $nw -Location "West US" -Country "United States" -StartTime "2017-10-05" -EndTime "2017-10-10" -AsJob
740740
$job | Wait-Job
@@ -768,18 +768,16 @@ function Test-ProvidersList
768768
# Setup
769769
$rgname = Get-ResourceGroupName
770770
$nwName = Get-ResourceName
771-
$rglocation = Get-ProviderLocation ResourceManagement
772771
$resourceTypeParent = "Microsoft.Network/networkWatchers"
773-
$location = "westcentralus"
772+
$location = "westus"
774773

775774
try
776775
{
777776
# Create the resource group
778-
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
779-
780-
# Create the Network Watcher
781-
$tags = @{"key1" = "value1"; "key2" = "value2"}
782-
$nw = Get-DeleteAndCreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $rgname -tags $tags
777+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "testval" }
778+
779+
# Get Network Watcher
780+
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $rgname
783781

784782
$job = Get-AzureRmNetworkWatcherReachabilityProvidersList -NetworkWatcher $nw -Location "West US" -Country "United States" -AsJob
785783
$job | Wait-Job
@@ -881,20 +879,8 @@ function Test-ConnectionMonitor
881879
#Query connection monitor
882880
Get-AzureRmNetworkWatcherConnectionMonitorReport -NetworkWatcher $nw -Name $cmName1
883881

884-
#Get connection monitor list
885-
$cmList = Get-AzureRmNetworkWatcherConnectionMonitor -NetworkWatcher $nw
886-
887-
#Validation
888-
Assert-AreEqual $cmList.Count 2
889-
890882
#Remove connection monitor
891883
Remove-AzureRmNetworkWatcherConnectionMonitor -NetworkWatcher $nw -Name $cmName1
892-
893-
#Get connection monitor list
894-
$cmList = Get-AzureRmNetworkWatcherConnectionMonitor -NetworkWatcher $nw
895-
896-
#Validation
897-
Assert-AreEqual $cmList.Count 1
898884
}
899885
finally
900886
{

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/NetworkWatcherTests.ps1

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

15+
<#
16+
.SYNOPSIS
17+
Deployment of new Network Watcher.
18+
#>
19+
function DeleteIfExistsNetworkWatcher($location)
20+
{
21+
# Get Network Watcher
22+
$nwlist = Get-AzureRmNetworkWatcher
23+
foreach ($i in $nwlist)
24+
{
25+
if($i.Location -eq "$location")
26+
{
27+
$nw=$i
28+
}
29+
}
30+
31+
# Delete Network Watcher if existing nw
32+
if ($nw)
33+
{
34+
$job = Remove-AzureRmNetworkWatcher -NetworkWatcher $nw -AsJob
35+
$job | Wait-Job
36+
}
37+
}
38+
1539
<#
1640
.SYNOPSIS
1741
Tests creating new simple public networkinterface.
@@ -21,39 +45,40 @@ function Test-NetworkWatcherCRUD
2145
# Setup
2246
$rgname = Get-ResourceGroupName
2347
$nwName = Get-ResourceName
24-
$rglocation = Get-ProviderLocation ResourceManagement
48+
$rglocation = Get-ProviderLocation ResourceManagement
2549
$resourceTypeParent = "Microsoft.Network/networkWatchers"
2650
$location = "westus"
2751

2852
try
2953
{
30-
# Create the resource group
31-
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
54+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
3255

56+
DeleteIfExistsNetworkWatcher -location $location
57+
3358
# Create the Network Watcher
3459
$tags = @{"key1" = "value1"; "key2" = "value2"}
3560
$nw = New-AzureRmNetworkWatcher -Name $nwName -ResourceGroupName $rgname -Location $location -Tag $tags
3661

3762
Assert-AreEqual $nw.Name $nwName
3863
Assert-AreEqual "Succeeded" $nw.ProvisioningState
39-
64+
4065
# Get Network Watcher
4166
$getNW = Get-AzureRmNetworkWatcher -ResourceGroupName $rgname -Name $nwName
42-
67+
4368
Assert-AreEqual $getNW.Name $nwName
4469
Assert-AreEqual "Succeeded" $nw.ProvisioningState
45-
70+
4671
# List Network Watchers
4772
$listNWByRg = Get-AzureRmNetworkWatcher -ResourceGroupName $rgname
4873
$listNW = Get-AzureRmNetworkWatcher
49-
74+
5075
Assert-AreEqual 1 @($listNWByRg).Count
51-
76+
5277
# Delete Network Watcher
5378
$job = Remove-AzureRmNetworkWatcher -ResourceGroupName $rgname -name $nwName -AsJob
54-
$job | Wait-Job
55-
$delete = $job | Receive-Job
56-
79+
$job | Wait-Job
80+
$delete = $job | Receive-Job
81+
5782
$list = Get-AzureRmNetworkWatcher -ResourceGroupName $rgname
5883
Assert-AreEqual 0 @($list).Count
5984
}

0 commit comments

Comments
 (0)