Skip to content

Commit 1816872

Browse files
authored
[SQL] Add managed instances external governance status update (#23914)
* * Added a new cmdlet for Azure SQL Managed Instance refresh external governance status - 'Invoke-AzSqlInstanceExternalGovernanceStatusRefresh' * Added related help file for new cmdlet * Updated `Get-AzSqlInstance` to support returning the `ExternalGovernanceStatus` property * Adds support for Parameter sets - ResourceId or MI object. * Add test + recording * Fix and extend tests to cover different ways how it is possible to call the cmdlet * Rename Parameter sets to reflect the cmdlet verb. * Adding test assert for getting External Governance status * Fix the help file - remove the prompt of example Fix missing default parameter set. Include correct link to online version of help
1 parent f795579 commit 1816872

13 files changed

+2855
-2
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
/// <summary>
23+
/// Tests for Invoke-AzSqlInstanceExternalGovernanceStatusRefresh
24+
/// </summary>
25+
public class RefreshSqlInstanceExternalGovernanceCmdletTests : SqlTestRunner
26+
{
27+
public RefreshSqlInstanceExternalGovernanceCmdletTests(ITestOutputHelper output) : base(output)
28+
{
29+
}
30+
31+
[Fact]
32+
[Trait(Category.AcceptanceType, Category.CheckIn)]
33+
public void TestSqlInstanceRefreshExternalGovernanceCmdlet()
34+
{
35+
TestRunner.RunTestScript("Test-RefreshSqlInstanceExternalGovernanceCmdlet");
36+
}
37+
}
38+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)