Skip to content

Conversation

@maddieclayton
Copy link
Contributor

@maddieclayton maddieclayton commented Oct 5, 2017

Description

Creates a ResourceGroupCompleter. Shows the first 50 resource groups that match the string the user has types. Default resource group will be put first in the list if it has been set. #4665


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

@maddieclayton
Copy link
Contributor Author

@azuresdkci Test this please

try
{
var instance = AzureSession.Instance;
var client = instance.ClientFactory.CreateCustomArmClient<ResourceManagementClient>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staying the same as discussed offline

instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager),
instance.ClientFactory.GetCustomHandlers());
//var client = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
client.SubscriptionId = context.Subscription.Id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use this method, you will not need to set the subscription id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

{
if (resourceGroups.Result != null)
{
var resourceGroupList = resourceGroups.Result.ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why write it to a list instead of just using it in the ForEach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, here we are making a conscious decision to only use the first page of results each time. We should probably call this out with a comment. BTW - ho9w many resource groups are in the first page of results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how many are in the first page - it wasn't in any of the code or documentation about IPage or List and it's more than my biggest subscription (92). Not sure if there's another place I should look.


else
{
#if DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this if should surround the entire else clause


else
{
#if DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

{
if (defaultResourceGroup != null)
{
if (resourceGroupNames.Contains(defaultResourceGroup))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the default resource group is on page 2 of the results? Seems like we should always include the defautl resource group at the beginning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user types out part of a name not including the default resource group, I think it makes sense not to include the default resource group. Let me know if I should include it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but it still could be in the second page of results

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still waiting to hear back from the Resources team about if it is possible to query Resource Groups by name

public void ReturnsEmptyListWhenNoResourceGroupsExist()
{
IList<string> resourceGroupsReturned = new List<string>();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra lines between statements.

{
IList<string> resourceGroupsReturned = new List<string>();
resourceGroupsReturned.Add("test1");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra lines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(apply everywhere in this file)

resourceGroupsReturned.Add("test3");
resourceGroupsReturned.Add("test4");

Assert.Equal(ResourceGroupCompleterAttribute.GetResourceGroups(resourceGroupsReturned, null), new string[] { "test1", "test2", "test3", "test4" });
Copy link
Member

@markcowl markcowl Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using Assert.Collection for succinctly testing the properties of a known collection and its elements, when in a known order. Note this this is advisroy only (and prompting you to check out the assertiosn available int eh xunit library)

{
if (defaultResourceGroup != null)
{
if (resourceGroupNames.Contains(defaultResourceGroup))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but it still could be in the second page of results

{
IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext;
var resourceGroupNamesCopy = ResourceGroupNames;
if (context.ExtendedProperties.ContainsKey(Resources.DefaultResourceGroupKey))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use context.IsPropertySet

lock (_lock)
{
_resourceGroupNames = new List<string>();
IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long is this taking? I wonder if we will need to do some caching here. Let's discuss and decide how to proceed.

@cormacpayne
Copy link
Member

@maddieclayton there are merge conflicts after the namespace update

@maddieclayton
Copy link
Contributor Author

@maddieclayton
Copy link
Contributor Author

@markcowl Are there more changes that this PR needs?

Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments. Overall, this looks good.

}
}

return _resourceGroupNamesDictionary[contextHash];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, if we haven't previously cached a value and the call actually times out in production, this will fall through to here, which will null ref, I think. We probably need to store the result in a local variable and return that, with the default value beign returned if the call to list resource groups times out.

Copy link
Contributor Author

@maddieclayton maddieclayton Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
public class ResourceGroupCompleterUnitTests
{
[Fact]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test completely, we should think about throwing an exception from the client, verifying the behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@maddieclayton
Copy link
Contributor Author

@azuresdkci Test this please

@markcowl
Copy link
Member

@markcowl markcowl removed their assignment Oct 31, 2017
@maddieclayton maddieclayton merged commit 93dc1de into Azure:preview Nov 1, 2017
@maddieclayton maddieclayton deleted the ResourceCompleter1 branch November 1, 2017 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants