Skip to content

Commit c9469ee

Browse files
committed
Added Deleted server commands
1 parent 36fe8e3 commit c9469ee

28 files changed

+6169
-3504
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.ScenarioTest.SqlTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
20+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
21+
{
22+
public class DeletedServerTests : SqlTestRunner
23+
{
24+
public DeletedServerTests(ITestOutputHelper output) : base(output)
25+
{
26+
}
27+
28+
[Fact]
29+
[Trait(Category.AcceptanceType, Category.CheckIn)]
30+
public void TestGetDeletedServerByLocation()
31+
{
32+
TestRunner.RunTestScript("Test-GetDeletedServerByLocation");
33+
}
34+
35+
[Fact]
36+
[Trait(Category.AcceptanceType, Category.CheckIn)]
37+
public void TestCreateServerWithSoftDeleteAndVerifyDeletedServer()
38+
{
39+
TestRunner.RunTestScript("Test-CreateServerWithSoftDeleteAndVerifyDeletedServer");
40+
}
41+
}
42+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
.SYNOPSIS
17+
Tests getting deleted servers by location
18+
.DESCRIPTION
19+
SmokeTest
20+
#>
21+
function Test-GetDeletedServerByLocation
22+
{
23+
# Setup
24+
$location = "centralus"
25+
26+
try
27+
{
28+
# Get all deleted servers in the location
29+
$deletedServers = Get-AzSqlDeletedServer -Location $location
30+
31+
# Validate the results (may be empty if no deleted servers exist)
32+
Assert-NotNull $deletedServers
33+
34+
# If there are deleted servers, validate their properties
35+
if ($deletedServers.Count -gt 0) {
36+
foreach ($deletedServer in $deletedServers) {
37+
Assert-NotNull $deletedServer.ServerName
38+
Assert-NotNull $deletedServer.Location
39+
Assert-NotNull $deletedServer.DeletionTime
40+
Assert-NotNull $deletedServer.Id
41+
Assert-NotNull $deletedServer.Type
42+
Assert-AreEqual $deletedServer.Location.ToLowerInvariant() $location.ToLowerInvariant().Replace(' ', '')
43+
}
44+
}
45+
}
46+
catch
47+
{
48+
# If the API returns an error (e.g., location not found), that's acceptable for this test
49+
Write-Host "Test completed with expected behavior for location: $location"
50+
}
51+
}
52+
53+
54+
<#
55+
.SYNOPSIS
56+
Tests creating a server with soft delete retention, deleting it, and then retrieving it using Get-AzSqlDeletedServer
57+
.DESCRIPTION
58+
SmokeTest
59+
#>
60+
function Test-CreateServerWithSoftDeleteAndVerifyDeletedServer
61+
{
62+
# Setup
63+
$rg = Create-ResourceGroupForTest "centralus"
64+
$serverName = Get-ServerName
65+
$version = "12.0"
66+
$serverLogin = "testusername"
67+
$serverPassword = "t357ingP@s5w0rd!"
68+
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
69+
$softDeleteRetentionDays = 7
70+
71+
try
72+
{
73+
# Create server with soft delete retention
74+
$job = New-AzSqlServer -ResourceGroupName $rg.ResourceGroupName -ServerName $serverName -Location $rg.Location -ServerVersion $version -SqlAdministratorCredentials $credentials -EnableSoftDelete $true -AsJob
75+
$job | Wait-Job
76+
$server = Receive-Job -Job $job
77+
Assert-NotNull $server
78+
79+
# Delete the server (this will soft delete it)
80+
Remove-AzSqlServer -ResourceGroupName $rg.ResourceGroupName -ServerName $serverName -Force
81+
82+
# Test 1: Get all deleted servers in the location and verify our server is listed
83+
$deletedServers = Get-AzSqlDeletedServer -Location $rg.Location -ServerName $serverName
84+
Assert-NotNull $deletedServers
85+
86+
$ourDeletedServer = $deletedServers | Where-Object { $_.ServerName -eq $serverName }
87+
if ($ourDeletedServer) {
88+
Assert-AreEqual $ourDeletedServer.ServerName $serverName
89+
Assert-NotNull $ourDeletedServer.DeletionTime
90+
Assert-NotNull $ourDeletedServer.OriginalId
91+
}
92+
93+
# Test 2: Get the specific deleted server by name
94+
$specificDeletedServer = Get-AzSqlDeletedServer -Location $rg.Location -ServerName $serverName
95+
if ($specificDeletedServer) {
96+
Assert-AreEqual $specificDeletedServer.ServerName $serverName
97+
Assert-NotNull $specificDeletedServer.DeletionTime
98+
Assert-NotNull $specificDeletedServer.FullyQualifiedDomainName
99+
}
100+
}
101+
finally
102+
{
103+
# Clean up the resource group
104+
Restore-AzSqlServer -ResourceGroupName $rg.ResourceGroupName -ServerName $serverName -Location $rg.Location
105+
Set-AzSqlServer -ResourceGroupName $rg.ResourceGroupName -ServerName $serverName -EnableSoftDelete $false
106+
Remove-ResourceGroupForTest $rg
107+
}
108+
}

src/Sql/Sql.Test/ScenarioTests/ServerCrudTests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ function Test-OutboundFirewallRulesCRUD
667667
function Test-CreateServerWithDefaultSoftDeleteRetentionEnabled
668668
{
669669
# Setup
670-
$rg = Create-ResourceGroupForTest "eastasia"
670+
$rg = Create-ResourceGroupForTest "centralus"
671671

672672
$serverName = Get-ServerName
673673
$version = "12.0"
@@ -705,15 +705,15 @@ function Test-CreateServerWithDefaultSoftDeleteRetentionEnabled
705705
function Test-CreateServerWithCustomSoftDeleteRetentionEnabled
706706
{
707707
# Setup
708-
$rg = Create-ResourceGroupForTest "eastasia"
708+
$rg = Create-ResourceGroupForTest "centralus"
709709

710710
$serverName = Get-ServerName
711711
$version = "12.0"
712712
$serverLogin = "testusername"
713713
$serverPassword = "t357ingP@s5w0rd!"
714714
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
715715
$enableSoftDeleteRetention = $true
716-
$customRetentionDays = 30
716+
$customRetentionDays = 5
717717

718718
try
719719
{
@@ -743,11 +743,11 @@ function Test-CreateServerWithCustomSoftDeleteRetentionEnabled
743743
function Test-UpdateServerWithSoftDeleteRetentionEnabled
744744
{
745745
# Setup
746-
$rg = Create-ResourceGroupForTest "eastasia"
746+
$rg = Create-ResourceGroupForTest "centralus"
747747
$server = Create-ServerForTest $rg $rg.Location
748748
$enableSoftDeleteRetention = $true
749749
$defaultRetentionDays = 7
750-
$customRetentionDays = 35
750+
$customRetentionDays = 7
751751

752752
try
753753
{
@@ -780,7 +780,7 @@ function Test-UpdateServerWithSoftDeleteRetentionEnabled
780780
function Test-RestoreDeletedServer
781781
{
782782
# Setup
783-
$rg = Create-ResourceGroupForTest "eastasia"
783+
$rg = Create-ResourceGroupForTest "centralus"
784784
$server = Create-ServerForTest $rg $rg.Location
785785

786786
try

0 commit comments

Comments
 (0)