Skip to content

Commit

Permalink
[Synapse] - Use Az Powershell defined exception types and refine test…
Browse files Browse the repository at this point in the history
… cases (#14361)

* [Synapse] - Use Az PowerShell defined exception and re-record test cases

* Update help doc for Restore-AzSynapseSqlPool

* Update changelog

* Remove TODO comment

* Update session records

* Fix CI MacOS build error

* Update breaking change issues

Co-authored-by: Dongwei Wang <dongwwa@microsoft.com>
  • Loading branch information
idear1203 and Dongwei Wang authored Mar 2, 2021
1 parent 9a5e18f commit ea9ac21
Show file tree
Hide file tree
Showing 67 changed files with 23,332 additions and 11,737 deletions.
16 changes: 13 additions & 3 deletions src/Synapse/Synapse.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,20 @@ function Invoke-HandledCmdlet

<#
.SYNOPSIS
Creates the test environment needed to perform the Sql auditing tests
Creates the test environment needed to perform the Synapse SQL related tests
#>
function Create-TestEnvironmentWithParams ($params, $location, $denyAsNetworkRuleDefaultAction = $False)
function Create-SqlTestEnvironmentWithParams ($params, $location)
{
Create-BasicTestEnvironmentWithParams $params $location
New-AzSynapseSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -SqlPoolName $params.sqlPoolName -PerformanceLevel $params.perfLevel
Wait-Seconds 10
}

<#
.SYNOPSIS
Creates the test environment needed to perform the Synapse tests
#>
function Create-TestEnvironmentWithParams ($params, $location)
{
Create-BasicTestEnvironmentWithParams $params $location
Wait-Seconds 10
Expand All @@ -135,5 +146,4 @@ function Create-BasicTestEnvironmentWithParams ($params, $location)
$workspacePassword = $params.pwd
$credentials = new-object System.Management.Automation.PSCredential($workspaceLogin, ($workspacePassword | ConvertTo-SecureString -asPlainText -Force))
New-AzSynapseWorkspace -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Location $location -SqlAdministratorLoginCredential $credentials -DefaultDataLakeStorageAccountName $params.storageAccountName -DefaultDataLakeStorageFilesystem $params.fileSystemName
New-AzSynapseSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -SqlPoolName $params.sqlPoolName -PerformanceLevel $params.perfLevel
}
18 changes: 1 addition & 17 deletions src/Synapse/Synapse.Test/ScenarioTests/FirewallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,9 @@ public FirewallTests(Xunit.Abstractions.ITestOutputHelper output)
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSynapseFirewall()
{
string testResourceGroupName = SynapseTestBase.TestResourceGroupName;
if (string.IsNullOrEmpty(testResourceGroupName))
{
testResourceGroupName = nameof(TestResourceGroupName);
}

string testWorkspaceName = SynapseTestBase.TestWorkspaceName;
if (string.IsNullOrEmpty(testWorkspaceName))
{
testWorkspaceName = nameof(TestWorkspaceName);
}

SynapseTestBase.NewInstance.RunPsTest(
_logger,
string.Format(
"Test-SynapseFirewall -resourceGroupName '{0}' -workspaceName '{1}'",
"testResourceGroupName",
"testWorkspaceName"
));
"Test-SynapseFirewall");
}
}
}
53 changes: 45 additions & 8 deletions src/Synapse/Synapse.Test/ScenarioTests/FirewallTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Tests Synapse Firewall Lifecycle (Create, Update, Get, List, Delete).
#>
function Test-SynapseFirewall
{
param
(
$resourceGroupName = (Get-ResourceGroupName),
$workspaceName = (Get-SynapseWorkspaceName)
)
# Setup
$testSuffix = getAssetName
Create-FirewallRuleTestEnvironment $testSuffix
$params = Get-FirewallRuleTestEnvironmentParameters $testSuffix

$resourceGroupName = $params.rgname
$workspaceName = $params.workspaceName

try
{
$resourceGroupName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("resourceGroupName", $resourceGroupName)
$workspaceName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("workspaceName", $workspaceName)
$workspace = Get-AzSynapseWorkspace -resourceGroupName $resourceGroupName -Name $workspaceName
$firewallRuleName = "originRuleName"
$StartIpAddress = "0.0.0.0"
Expand Down Expand Up @@ -51,6 +51,43 @@ function Test-SynapseFirewall
}
finally
{
# cleanup the firewallRuleName created by test code.
# Cleanup
Remove-FirewallRuleTestEnvironment $testSuffix
}
}

<#
.SYNOPSIS
Creates the test environment needed to perform the tests
#>
function Create-FirewallRuleTestEnvironment ($testSuffix)
{
$params = Get-FirewallRuleTestEnvironmentParameters $testSuffix
Create-TestEnvironmentWithParams $params $params.location
}

<#
.SYNOPSIS
Gets the values of the parameters used at the tests
#>
function Get-FirewallRuleTestEnvironmentParameters ($testSuffix)
{
return @{ rgname = "fw-cmdlet-test-rg" +$testSuffix;
workspaceName = "fw" +$testSuffix;
storageAccountName = "fwstorage" + $testSuffix;
fileSystemName = "fwcmdletfs" + $testSuffix;
loginName = "testlogin";
pwd = "testp@ssMakingIt1007Longer";
location = "westcentralus";
}
}

<#
.SYNOPSIS
Removes the test environment that was needed to perform the tests
#>
function Remove-FirewallRuleTestEnvironment ($testSuffix)
{
$params = Get-FirewallRuleTestEnvironmentParameters $testSuffix
Remove-AzResourceGroup -Name $params.rgname -Force
}
22 changes: 2 additions & 20 deletions src/Synapse/Synapse.Test/ScenarioTests/IntegrationRuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,9 @@ public IntegrationRuntimeTests(Xunit.Abstractions.ITestOutputHelper output)
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSelfHostedIntegrationRuntime()
{
string testResourceGroupName = SynapseTestBase.TestResourceGroupName;
if (string.IsNullOrEmpty(testResourceGroupName))
{
testResourceGroupName = nameof(TestResourceGroupName);
}

string testWorkspaceName = SynapseTestBase.TestWorkspaceName;
if (string.IsNullOrEmpty(testWorkspaceName))
{
testWorkspaceName = nameof(TestWorkspaceName);
}

SynapseTestBase.NewInstance.RunPsTest(
_logger,
string.Format(
"Test-SelfHosted-IntegrationRuntime -resourceGroupName '{0}' -workspaceName '{1}'",
testResourceGroupName,
testWorkspaceName));
"Test-SelfHosted-IntegrationRuntime");
}

[Fact]
Expand All @@ -70,10 +55,7 @@ public void TestAzureIntegrationRuntime()

SynapseTestBase.NewInstance.RunPsTest(
_logger,
string.Format(
"Test-Azure-IntegrationRuntime -resourceGroupName '{0}' -workspaceName '{1}'",
testResourceGroupName,
testWorkspaceName));
"Test-Azure-IntegrationRuntime");
}

[Fact]
Expand Down
96 changes: 66 additions & 30 deletions src/Synapse/Synapse.Test/ScenarioTests/IntegrationRuntimeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ Deletes the created integration runtime at the end.
#>
function Test-SelfHosted-IntegrationRuntime
{
param
(
$resourceGroupName = (Get-ResourceGroupName),
$workspaceName = (Get-SynapseWorkspaceName),
$irname = "selfhosted-test-integrationruntime"
)
# Setup
$testSuffix = getAssetName
Create-WorkspaceTestEnvironment $testSuffix
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix

$resourceGroupName = $params.rgname
$workspaceName = $params.workspaceName
$irname = "selfhosted-test-integrationruntime"

try
{
$resourceGroupName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("resourceGroupName", $resourceGroupName)
$workspaceName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("workspaceName", $workspaceName)

$actual = Set-AzSynapseIntegrationRuntime -ResourceGroupName $resourceGroupName `
-WorkspaceName $workspaceName `
-Name $irname `
Expand Down Expand Up @@ -58,7 +57,8 @@ function Test-SelfHosted-IntegrationRuntime
}
finally
{
Invoke-HandledCmdlet -Command {Remove-AzSynapseIntegrationRuntime -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $irname} -IgnoreFailures
# Cleanup
Remove-WorkspaceTestEnvironment $testSuffix
}
}

Expand All @@ -69,18 +69,17 @@ Deletes the created integration runtime at the end.
#>
function Test-Azure-IntegrationRuntime
{
param
(
$resourceGroupName = (Get-ResourceGroupName),
$workspaceName = (Get-SynapseWorkspaceName),
$irname = "test-ManagedElastic-integrationruntime"
)
# Setup
$testSuffix = getAssetName
Create-WorkspaceTestEnvironment $testSuffix
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix

$resourceGroupName = $params.rgname
$workspaceName = $params.workspaceName
$irname = "test-ManagedElastic-integrationruntime"

try
{
$resourceGroupName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("resourceGroupName", $resourceGroupName)
$workspaceName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("workspaceName", $workspaceName)

$description = "ManagedElastic"

$actual = Set-AzSynapseIntegrationRuntime -ResourceGroupName $resourceGroupName `
Expand All @@ -100,7 +99,8 @@ function Test-Azure-IntegrationRuntime
}
finally
{
Invoke-HandledCmdlet -Command {Remove-AzSynapseIntegrationRuntime -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $irname} -IgnoreFailures
# Cleanup
Remove-WorkspaceTestEnvironment $testSuffix
}
}

Expand All @@ -110,18 +110,17 @@ Creates a self-hosted integration runtime and then does piping operations.
#>
function Test-IntegrationRuntime-Piping
{
param
(
$resourceGroupName = (Get-ResourceGroupName),
$workspaceName = (Get-SynapseWorkspaceName),
$irname = "test-integrationruntime-for-piping"
)
# Setup
$testSuffix = getAssetName
Create-WorkspaceTestEnvironment $testSuffix
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix

$resourceGroupName = $params.rgname
$workspaceName = $params.workspaceName
$irname = "test-integrationruntime-for-piping"

try
{
$resourceGroupName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("resourceGroupName", $resourceGroupName)
$workspaceName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("workspaceName", $workspaceName)

$result = Set-AzSynapseIntegrationRuntime -ResourceGroupName $resourceGroupName `
-WorkspaceName $workspaceName `
-Name $irname `
Expand All @@ -136,6 +135,43 @@ function Test-IntegrationRuntime-Piping
}
finally
{
Invoke-HandledCmdlet -Command {Remove-AzSynapseIntegrationRuntime -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $irname} -IgnoreFailures
# Cleanup
Remove-WorkspaceTestEnvironment $testSuffix
}
}

<#
.SYNOPSIS
Creates the test environment needed to perform the tests
#>
function Create-WorkspaceTestEnvironment ($testSuffix)
{
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix
Create-TestEnvironmentWithParams $params $params.location
}

<#
.SYNOPSIS
Gets the values of the parameters used at the tests
#>
function Get-WorkspaceTestEnvironmentParameters ($testSuffix)
{
return @{ rgname = "ws-cmdlet-test-rg" +$testSuffix;
workspaceName = "ws" +$testSuffix;
storageAccountName = "wsstorage" + $testSuffix;
fileSystemName = "wscmdletfs" + $testSuffix;
loginName = "testlogin";
pwd = "testp@ssMakingIt1007Longer";
location = "westcentralus";
}
}

<#
.SYNOPSIS
Removes the test environment that was needed to perform the tests
#>
function Remove-WorkspaceTestEnvironment ($testSuffix)
{
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix
Remove-AzResourceGroup -Name $params.rgname -Force
}
17 changes: 1 addition & 16 deletions src/Synapse/Synapse.Test/ScenarioTests/SparkPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,9 @@ public SparkPoolTests(Xunit.Abstractions.ITestOutputHelper output)
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSynapseSparkPool()
{
string testResourceGroupName = SynapseTestBase.TestResourceGroupName;
if (string.IsNullOrEmpty(testResourceGroupName))
{
testResourceGroupName = nameof(TestResourceGroupName);
}

string testWorkspaceName = SynapseTestBase.TestWorkspaceName;
if (string.IsNullOrEmpty(testWorkspaceName))
{
testWorkspaceName = nameof(TestWorkspaceName);
}

SynapseTestBase.NewInstance.RunPsTest(
_logger,
string.Format(
"Test-SynapseSparkPool -resourceGroupName '{0}' -workspaceName '{1}'",
testResourceGroupName,
testWorkspaceName));
"Test-SynapseSparkPool");
}
}
}
Loading

0 comments on commit ea9ac21

Please sign in to comment.