Skip to content

Add AksTestRunner and replace TestController #17962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/AksTestRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using System.Reflection;
using System.IO;
using Microsoft.Azure.Management.Internal.Resources;
using Microsoft.Azure.Management.ContainerService;
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0;
using Microsoft.Azure.Commands.TestFx;
using Xunit.Abstractions;

namespace Commands.Aks.Test.ScenarioTests
{
public class AksTestRunner
{
protected readonly ITestRunner TestRunner;

protected AksTestRunner(ITestOutputHelper output)
{
TestRunner = TestManager.CreateInstance (output)
.WithNewPsScriptFilename ($"{GetType().Name}.ps1")
.WithProjectSubfolderForTests ("ScenarioTests")
.WithCommonPsScripts (new[]
{
@"Common.ps1",
@"../AzureRM.Resources.ps1"
})
.WithNewRmModules (helper => new[]
{
helper.RMProfileModule,
helper.GetRMModulePath("Az.Aks.psd1")
})
.WithNewRecordMatcherArguments (
userAgentsToIgnore: new Dictionary<string, string>
{
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2017-05-10"},
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10"}
},
resourceProviders: new Dictionary<string, string>
{
{"Microsoft.Resources", null},
{"Microsoft.Features", null},
{"Microsoft.Authorization", null}
}
).WithMockContextAction(() =>
{
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback)
{
AzureSession.Instance.DataStore = new MemoryDataStore();
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);
var subscription = HttpMockServer.Variables["SubscriptionId"];
AzureSession.Instance.DataStore.WriteFile(Path.Combine(home, ".ssh", "id_rsa.pub"), File.ReadAllText(dir + "/Fixtures/id_rsa.pub"));
var jsonOutput = @"{""" + subscription + @""":{ ""service_principal"":""foo"",""client_secret"":""bar""}}";
AzureSession.Instance.DataStore.WriteFile(Path.Combine(home, ".azure", "acsServicePrincipal.json"), jsonOutput);
}
else if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
AzureSession.Instance.DataStore = new MemoryDataStore();
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);
var subscription = HttpMockServer.Variables["SubscriptionId"];
var currentEnvironment = TestEnvironmentFactory.GetTestEnvironment();
string spn = null;
string spnSecret = null;
if (currentEnvironment.ConnectionString.KeyValuePairs.ContainsKey("ServicePrincipal"))
{
spn = currentEnvironment.ConnectionString.KeyValuePairs["ServicePrincipal"];
}
if (currentEnvironment.ConnectionString.KeyValuePairs.ContainsKey("ServicePrincipalSecret"))
{
spnSecret = currentEnvironment.ConnectionString.KeyValuePairs["ServicePrincipalSecret"];
}
AzureSession.Instance.DataStore.WriteFile(Path.Combine(home, ".ssh", "id_rsa.pub"), File.ReadAllText(dir + "/Fixtures/id_rsa.pub"));
var jsonOutput = @"{""" + subscription + @""":{ ""service_principal"":""" + spn + @""",""client_secret"":"""+ spnSecret + @"""}}";
AzureSession.Instance.DataStore.WriteFile(Path.Combine(home, ".azure", "acsServicePrincipal.json"), jsonOutput);
}
}
)
.Build();
}
}
}
29 changes: 11 additions & 18 deletions src/Aks/Aks.Test/ScenarioTests/KubernetesTests.cs
Original file line number Diff line number Diff line change
@@ -1,83 +1,76 @@
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Commands.Aks.Test.ScenarioTests
{
public class KubernetesTests : RMTestBase
public class KubernetesTests : AksTestRunner
{
XunitTracingInterceptor _logger;
public KubernetesTests(ITestOutputHelper output)
public KubernetesTests(ITestOutputHelper output) : base(output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
TestExecutionHelpers.SetUpSessionAndProfile();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSimpleAzureKubernetes()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAksSimple");
TestRunner.RunTestScript("Test-NewAzAksSimple");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAzureKubernetes()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAks");
TestRunner.RunTestScript("Test-NewAzAks");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewAzureKubernetesByServicePrincipal()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAksByServicePrincipal");
TestRunner.RunTestScript("Test-NewAzAksByServicePrincipal");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAzureKubernetesAddons()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAksAddons");
TestRunner.RunTestScript("Test-NewAzAksAddons");
}

[Fact(Skip = "Please make sure you have graph directory.read permission which is required for grant acrpull permission.")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewAzAksWithAcr()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAksWithAcr");
TestRunner.RunTestScript("Test-NewAzAksWithAcr");
}

[Fact(Skip = "Updating service principal profile is not allowed on MSI cluster.")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestResetAzureKubernetesServicePrincipal()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ResetAzureKubernetesServicePrincipal");
TestRunner.RunTestScript("Test-ResetAzureKubernetesServicePrincipal");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpgradeKubernetesVersion()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpgradeKubernetesVersion");
TestRunner.RunTestScript("Test-UpgradeKubernetesVersion");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestLoadBalancer()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-LoadBalancer");
TestRunner.RunTestScript("Test-LoadBalancer");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestApiServiceAccess()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ApiServiceAccess");
TestRunner.RunTestScript("Test-ApiServiceAccess");
}
}
}
15 changes: 4 additions & 11 deletions src/Aks/Aks.Test/ScenarioTests/NodePoolTests.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Commands.Aks.Test.ScenarioTests
{
public class NodePoolTests : RMTestBase
public class NodePoolTests : AksTestRunner
{
XunitTracingInterceptor _logger;
public NodePoolTests(ITestOutputHelper output)
public NodePoolTests(ITestOutputHelper output) : base(output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
TestExecutionHelpers.SetUpSessionAndProfile();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAksNodePool()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewNodePool");
TestRunner.RunTestScript("Test-NewNodePool");
}
}
}
142 changes: 0 additions & 142 deletions src/Aks/Aks.Test/ScenarioTests/TestController.cs

This file was deleted.