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+ }
0 commit comments