|
| 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 | +<# |
| 17 | + .SYNOPSIS |
| 18 | + Tests refresh external governance status |
| 19 | +#> |
| 20 | + |
| 21 | +function Test-RefreshSqlInstanceExternalGovernanceCmdlet ($location = "eastus2euap") |
| 22 | +{ |
| 23 | + #Test scenario |
| 24 | + try |
| 25 | + { |
| 26 | + # ------------------------------ Setup |
| 27 | + Write-Debug "Creating test MI" |
| 28 | + $rg = Create-ResourceGroupForTest |
| 29 | + $rgName = $rg.ResourceGroupName |
| 30 | + $managedInstance = Create-ManagedInstanceForTest $rg |
| 31 | + $managedInstanceName = $managedInstance.ManagedInstanceName |
| 32 | + |
| 33 | + # ------------------------------ Get the MI |
| 34 | + |
| 35 | + Write-Debug "Getting the created MI $managedInstanceName" |
| 36 | + $instance = Get-AzSqlInstance -ResourceGroupName $rgName -Name $managedInstanceName |
| 37 | + $instanceId = $instance.Id |
| 38 | + $instanceName = $instance.ManagedInstanceName |
| 39 | + |
| 40 | + Assert-AreEqual $instance.ExternalGovernanceStatus "Disabled" |
| 41 | + |
| 42 | + # ------------------------------ Test by passing in the instance object |
| 43 | + |
| 44 | + Write-Debug "Test by passing in the instance object" |
| 45 | + $result = Get-AzSqlInstance -ResourceGroupName $rgName -Name $managedInstanceName | Invoke-AzSqlInstanceExternalGovernanceStatusRefresh |
| 46 | + |
| 47 | + Write-Debug ('$result is ' + (ConvertTo-Json $result)) |
| 48 | + Assert-NotNull $result |
| 49 | + |
| 50 | + Assert-AreEqual $result.Status "Succeeded" |
| 51 | + Assert-AreEqual $result.InstanceName $instanceName |
| 52 | + |
| 53 | + # ------------------------------ Test by passing in the resource id |
| 54 | + Write-Debug "Test by passing in the resource id" |
| 55 | + $result = Invoke-AzSqlInstanceExternalGovernanceStatusRefresh -ResourceId $instanceId |
| 56 | + |
| 57 | + Write-Debug ('$result is ' + (ConvertTo-Json $result)) |
| 58 | + Assert-NotNull $result |
| 59 | + |
| 60 | + Assert-AreEqual $result.Status "Succeeded" |
| 61 | + Assert-AreEqual $result.InstanceName $instanceName |
| 62 | + |
| 63 | + # ------------------------------ Test by passing in the resource group name and instance name |
| 64 | + Write-Debug "Test by passing in the name and resource group" |
| 65 | + $result = Invoke-AzSqlInstanceExternalGovernanceStatusRefresh -ResourceGroupName $rgName -InstanceName $instanceName |
| 66 | + Write-Debug ('$result is ' + (ConvertTo-Json $result)) |
| 67 | + Assert-NotNull $result |
| 68 | + |
| 69 | + Assert-AreEqual $result.Status "Succeeded" |
| 70 | + Assert-AreEqual $result.InstanceName $instanceName |
| 71 | + } |
| 72 | + finally |
| 73 | + { |
| 74 | + Remove-ResourceGroupForTest $rg |
| 75 | + } |
| 76 | +} |
0 commit comments