Skip to content

Commit a047451

Browse files
committed
Add LocalNetworkGateway tests and session records
1 parent ae681dc commit a047451

File tree

4 files changed

+876
-0
lines changed

4 files changed

+876
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests
17+
{
18+
using Microsoft.Azure.Commands.Common.Authentication;
19+
using Microsoft.Azure.Test;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Microsoft.WindowsAzure.Management;
22+
using Microsoft.WindowsAzure.Management.Compute;
23+
using Microsoft.WindowsAzure.Management.Network;
24+
using Microsoft.WindowsAzure.Management.Storage;
25+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
26+
using System;
27+
using System.Collections.Generic;
28+
using System.IO;
29+
using System.Linq;
30+
using Xunit;
31+
32+
public class GatewayScenarioTests
33+
{
34+
private readonly EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
35+
36+
[Fact]
37+
[Trait(Category.Service, Category.Network)]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void LocalNetworkGateway()
40+
{
41+
RunPowerShellTest("Test-LocalNetworkGateway");
42+
}
43+
44+
[Fact]
45+
[Trait(Category.Service, Category.Network)]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
47+
public void LocalNetworkGatewayBgp()
48+
{
49+
RunPowerShellTest("Test-LocalNetworkGatewayBgp");
50+
}
51+
52+
#region Test setup
53+
54+
protected void SetupManagementClients()
55+
{
56+
var client = TestBase.GetServiceClient<NetworkManagementClient>(new RDFETestEnvironmentFactory());
57+
var client2 = TestBase.GetServiceClient<ManagementClient>(new RDFETestEnvironmentFactory());
58+
var client3 = TestBase.GetServiceClient<StorageManagementClient>(new RDFETestEnvironmentFactory());
59+
var client4 = TestBase.GetServiceClient<ComputeManagementClient>(new RDFETestEnvironmentFactory());
60+
helper.SetupManagementClients(client, client2, client3, client4);
61+
}
62+
63+
protected void RunPowerShellTest(params string[] scripts)
64+
{
65+
using (UndoContext context = UndoContext.Current)
66+
{
67+
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
68+
69+
List<string> modules = Directory.GetFiles("ScenarioTests\\Gateway".AsAbsoluteLocation(), "*.ps1").ToList();
70+
modules.AddRange(Directory.GetFiles("ScenarioTests".AsAbsoluteLocation(), "*.ps1"));
71+
72+
SetupManagementClients();
73+
74+
helper.SetupEnvironment(AzureModule.AzureServiceManagement);
75+
helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());
76+
77+
helper.RunPowerShellTest(scripts);
78+
}
79+
}
80+
#endregion
81+
}
82+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
########################################################################### Gateway tests ###################################################################
16+
17+
<#
18+
.SYNOPSIS
19+
Tests for local network gateway right now
20+
#>
21+
22+
function Test-LocalNetworkGateway
23+
{
24+
# Setup
25+
$lngname = getAssetName
26+
$location="West US"
27+
28+
$subscription = Get-AzureSubscription -Current
29+
Set-AzureSubscription -SubscriptionId $subscription.SubscriptionId
30+
31+
# Create a local network gateway
32+
$ipAddr = "1.2.3.4"
33+
$addrSpace = "10.0.0.0/8"
34+
New-AzureLocalNetworkGateway -GatewayName $lngname -IpAddress $ipAddr -AddressSpace $addrSpace
35+
36+
# Retrieve a list of local network gateways, and get the one created above by name
37+
$lnglist = Get-AzureLocalNetworkGateway
38+
$lng = $lnglist | Where-Object { $_.GatewayName -eq $lngname }
39+
Assert-AreEqual $lng.IpAddress $ipAddr
40+
Assert-AreEqual $lng.AddressSpace $addrSpace
41+
42+
# Retrieve the local network gateway by ID
43+
$lng = Get-AzureLocalNetworkGateway -GatewayId $lng.GatewayId
44+
Assert-AreEqual $lng.IpAddress $ipAddr
45+
Assert-AreEqual $lng.AddressSpace $addrSpace
46+
47+
# Delete the local network gateway
48+
Remove-AzureLocalNetworkGateway -GatewayId $lng.GatewayId
49+
}
50+
51+
function Test-LocalNetworkGatewayBgp
52+
{
53+
# Setup
54+
$lngname = getAssetName
55+
$location="West US"
56+
57+
$subscription = Get-AzureSubscription -Current
58+
Set-AzureSubscription -SubscriptionId $subscription.SubscriptionId
59+
60+
# Create a local network gateway
61+
$ipAddr = "1.2.3.4"
62+
$addrSpace = "10.0.0.0/8"
63+
$asn = "1234"
64+
$bgpaddr = "10.0.0.1"
65+
New-AzureLocalNetworkGateway -GatewayName $lngname -IpAddress $ipAddr -AddressSpace $addrSpace -Asn $asn -BgpPeeringAddress $bgpaddr
66+
67+
# Retrieve a list of local network gateways, and get the one created above by name
68+
$lnglist = Get-AzureLocalNetworkGateway
69+
$lng = $lnglist | Where-Object { $_.GatewayName -eq $lngname }
70+
Assert-AreEqual $lng.IpAddress $ipAddr
71+
Assert-AreEqual $lng.AddressSpace $addrSpace
72+
Assert-AreEqual $lng.Asn $asn
73+
Assert-AreEqual $lng.BgpPeeringAddress $bgpaddr
74+
75+
# Retrieve the local network gateway by ID
76+
$lng = Get-AzureLocalNetworkGateway -GatewayId $lng.GatewayId
77+
Assert-AreEqual $lng.IpAddress $ipAddr
78+
Assert-AreEqual $lng.AddressSpace $addrSpace
79+
Assert-AreEqual $lng.Asn $asn
80+
Assert-AreEqual $lng.BgpPeeringAddress $bgpaddr
81+
82+
# Delete the local network gateway
83+
Remove-AzureLocalNetworkGateway -GatewayId $lng.GatewayId
84+
}

src/ServiceManagement/Network/Commands.Network.Test/SessionRecords/Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests.GatewayScenarioTests/LocalNetworkGateway.json

Lines changed: 355 additions & 0 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Network/Commands.Network.Test/SessionRecords/Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests.GatewayScenarioTests/LocalNetworkGatewayBgp.json

Lines changed: 355 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)