-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Get/Set/Clear-AzureRmDefault Cmdlets #4707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
95cb16c
Initial work on defaults
azdevxps 53b4af1
Add all cmdlets
f443ef6
Changes to cmdlets and adding tests
azdevxps 0529806
add tests and help files
azdevxps 07fcecd
Merge branch 'preview' of https://github.com/Azure/azure-powershell i…
azdevxps 26202e9
Add scenario tests
azdevxps 29f9957
cleanup
azdevxps c286f39
include all changes in shouldprocess
azdevxps a995b7f
add changes to changelog
azdevxps 09c92ab
update csproj
73cb902
text error
cbe3a6a
add missing sessionfiles
azdevxps 8181bba
Merge branch 'Default' of https://github.com/maddieclayton/azure-powe…
azdevxps 4e3bc99
add required files
779ab67
change session files
azdevxps a093169
csproj changes
azdevxps 7eda1b6
fix build error
2d781fd
Partially enlightened after reviewing another cmdlet pr
azdevxps e6a3a92
Merge branch 'Default' of https://github.com/maddieclayton/azure-powe…
azdevxps a827f10
some fixes
azdevxps 6317ceb
changes to cmdlets
azdevxps 84fe87d
fix tests
azdevxps 05fe7c2
fix session records
azdevxps bd4cb0a
update help files
azdevxps 2db8da3
fix yaml bug
azdevxps 58d2cbd
Merge branch 'preview' into Default
a815e19
Add requested changes
azdevxps c481a9a
Merge branch 'Default' of https://github.com/maddieclayton/azure-powe…
azdevxps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/ResourceManager/Profile/Commands.Profile.Test/DefaultCmdletTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ResourceManager.Common; | ||
using Microsoft.Azure.Commands.Resources.Test.ScenarioTests; | ||
using Microsoft.Azure.Commands.ScenarioTest; | ||
using Microsoft.Azure.ServiceManagemenet.Common.Models; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||
using System.Threading; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.Azure.Commands.Profile.Test | ||
{ | ||
public class DefaultCmdletTests : RMTestBase | ||
{ | ||
private XunitTracingInterceptor xunitLogger; | ||
|
||
public DefaultCmdletTests(ITestOutputHelper output) | ||
{ | ||
TestExecutionHelpers.SetUpSessionAndProfile(); | ||
ResourceManagerProfileProvider.InitializeResourceManagerProfile(true); | ||
|
||
xunitLogger = new XunitTracingInterceptor(output); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void DefaultResourceGroup() | ||
{ | ||
ProfileController.NewInstance.RunPsTest(xunitLogger, "72f988bf-86f1-41af-91ab-2d7cd011db47", "Test-DefaultResourceGroup"); | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/ResourceManager/Profile/Commands.Profile.Test/DefaultCmdletTests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests cmdlets surrounding default resource group | ||
#> | ||
function Test-DefaultResourceGroup | ||
{ | ||
# Setup | ||
$rgname = Get-ResourceGroupName | ||
Clear-AzureRmDefault -ResourceGroup | ||
|
||
try | ||
{ | ||
# Test GetDefault when default not set | ||
$output = Get-AzureRmDefault | ||
Assert-Null($output) | ||
$output = Get-AzureRmDefault -ResourceGroup | ||
Assert-Null($output) | ||
$storedValue = (Get-AzureRmContext).ExtendedProperties["Default Resource Group"] | ||
Assert-Null($storedValue) | ||
|
||
# Test Resoure Group created when it doesn't exist | ||
$output = Set-AzureRmDefault -ResourceGroupName $rgname -Force | ||
$resourcegroup = Get-AzureRmResourceGroup -Name $rgname | ||
Assert-AreEqual $output.Name $resourcegroup.ResourceGroupName | ||
$context = Get-AzureRmContext | ||
$storedValue = $context.ExtendedProperties["Default Resource Group"] | ||
Assert-AreEqual $storedValue $output.Name | ||
|
||
# Test GetDefault when default is set | ||
$output = Get-AzureRmDefault | ||
Assert-AreEqual $output.Name $resourceGroup.ResourceGroupName | ||
$output = Get-AzureRmDefault -ResourceGroup | ||
Assert-AreEqual $output.Name $resourceGroup.ResourceGroupName | ||
|
||
# Test Clear-AzureRmDefault (no parameters shown) | ||
Clear-AzureRmDefault -Force | ||
$output = Get-AzureRmDefault | ||
Assert-Null($output) | ||
$context = Get-AzureRmContext | ||
$storedValue = $context.ExtendedProperties["Default Resource Group"] | ||
Assert-Null($storedValue) | ||
|
||
# Test SetDefault when resource group exists | ||
$output = Set-AzureRmDefault -ResourceGroupName $rgname | ||
Assert-AreEqual $output.Name $resourcegroup.ResourceGroupName | ||
$context = Get-AzureRmContext | ||
$storedValue = $context.ExtendedProperties["Default Resource Group"] | ||
Assert-AreEqual $storedValue $output.Name | ||
|
||
# Test Clear-AzureRmDefault (no parameters shown) | ||
Clear-AzureRmDefault -ResourceGroup | ||
$output = Get-AzureRmDefault | ||
Assert-Null($output) | ||
$context = Get-AzureRmContext | ||
$storedValue = $context.ExtendedProperties["Default Resource Group"] | ||
Assert-Null($storedValue) | ||
} | ||
finally | ||
{ | ||
Clean-ResourceGroup($rgname) | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Gets valid resource group name | ||
#> | ||
function Get-ResourceGroupName | ||
{ | ||
return getAssetName | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Cleans the created resource groups | ||
#> | ||
function Clean-ResourceGroup($rgname) | ||
{ | ||
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback) { | ||
Remove-AzureRmResourceGroup -Name $rgname -Force | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need all of these resourcemanagemrnt clients? Seems like we can simplify to a single one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need both of them - one is being used in the test code, and one is being used in the cmdlet code.