Skip to content

Commit cb9f6ae

Browse files
author
Hovsep Mkrtchyan
committed
Added resource tests to CLU
1 parent fc89673 commit cb9f6ae

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing Resources in Azure ===\n"
4+
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6+
azure group create --name "$groupName" --location "$location"
7+
resourceName="CluResource"
8+
destinationGroupName=$groupName"Destination"
9+
10+
printf "\n2. Registering Resource Provider Namespace.\n"
11+
providerNamespace="Providers.Test"
12+
azure resource provider register --ProviderNamespace $providerNamespace --Force
13+
14+
printf "\n3. Creating a new Resource: %s.\n" "$resourceName"
15+
resourceType="$providerNamespace/statefulResources"
16+
tags='[{"Name": "testtag", "Value": "testvalue"}]'
17+
properties='{"administratorLogin": "adminuser", "administratorLoginPassword": "P@ssword1"}'
18+
apiversion="2014-04-01"
19+
azure resource create --Name $resourceName --Location $location --Tags "$tags" --ResourceGroupName $groupName --ResourceType $resourceType --PropertyObject "$properties" --ApiVersion $apiversion --Force
20+
21+
printf "\n4. Get information about Resource : %s.\n" "$resourceName"
22+
resourceInfo=$(azure resource get -n $resourceName)
23+
printf "\nValidating Resource name is: %s\n" "$resourceName"
24+
[ $(echo $resourceInfo | jq '.Name' --raw-output) == "$resourceName" ]
25+
26+
printf "\n5. Find Resource with name = %s and type =.\n" "$resourceName" "$resourceType"
27+
foundResource=$(azure resource find -n "clu" -t $resourceType)
28+
printf "\nValidating Resource name is: %s\n" "$resourceName"
29+
[ $(echo $foundResource | jq '.Name' --raw-output) == "$resourceName" ]
30+
31+
printf "\n6. Update Resource.\n"
32+
tagsUpdate='[{"Name": "testtagUpdated", "Value": "testvalueUpdated"}]'
33+
azure resource set --ResourceGroupName $groupName --ResourceName $resourceName --ResourceType $resourceType --Tags "$tagsUpdate" -f
34+
35+
printf "\n7. Move Resource to resource group: %s.\n" "$destinationGroupName"
36+
azure group create --name "$destinationGroupName" --location "$location"
37+
resourceId=$(echo $resourceInfo | jq '.Id')
38+
arrayId="[$resourceId]"
39+
azure resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f
40+
41+
printf "\n8. Removing resource: %s.\n" "$resourceName"
42+
foundResource=$(azure resource find -n "clu" -t $resourceType)
43+
resourceId=$(echo $foundResource | jq '.Id' --raw-output)
44+
azure resource remove --Id "$resourceId" -f

src/CLU/Commands.ResourceManager.Cmdlets/Extensions/JTokenExtensions.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ internal static PSObject ToPsObject(this JToken jtoken)
5454
{
5555
return null;
5656
}
57-
58-
// TODO CORECLR does not exist in coreclr50
59-
/*if (jtoken.Type != JTokenType.Object)
57+
58+
if (jtoken.Type != JTokenType.Object)
6059
{
61-
return new PSObject(JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken));
62-
}*/
60+
var retObject = new PSObject();
61+
retObject.Properties.Add(new PSNoteProperty(
62+
name: JTokenExtensions.ConvertToPascalCase(propertyName: jtoken.Type.ToString()),
63+
value: JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken)));
64+
return retObject;
65+
}
6366

6467
var jobject = (JObject)jtoken;
6568
var psObject = new PSObject();

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/Resource/GetAzureResourceCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
8888
/// <summary>
8989
/// Gets or sets the resource name parameter.
9090
/// </summary>
91-
[Alias("Name")]
91+
[Alias("Name", "n")]
9292
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name. e.g. to specify a database MyServer/MyDatabase.")]
9393
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name. e.g. to specify a database MyServer/MyDatabase.")]
9494
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name. e.g. to specify a database MyServer/MyDatabase.")]

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/Resource/NewAzureResourceCmdlet.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase
7272
[ValidateNotNullOrEmpty]
7373
[Alias("sku")]
7474
public Hashtable SkuObject { get; set; }
75-
76-
75+
7776
/// <summary>
7877
/// Gets or sets the tags.
7978
/// </summary>

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/ResourceManipulationCmdletBase.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,12 @@ public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBase
107107
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
108108
[Alias("f")]
109109
public SwitchParameter Force { get; set; }
110-
111-
/// <summary>
112-
/// Gets or sets the subscription id.
113-
/// </summary>
114-
public Guid SubscriptionId { get; set; }
115-
110+
116111
/// <summary>
117112
/// Initializes the default subscription id if needed.
118113
/// </summary>
119114
public ResourceManipulationCmdletBase()
120115
{
121-
if (string.IsNullOrEmpty(this.ResourceId))
122-
{
123-
this.SubscriptionId = DefaultContext.Subscription.Id;
124-
}
125116
}
126117

127118
protected override void OnProcessRecord()
@@ -149,7 +140,7 @@ protected string GetResourceId()
149140
private string GetResourceIdWithoutParentResource()
150141
{
151142
return ResourceIdUtility.GetResourceId(
152-
subscriptionId: this.SubscriptionId,
143+
subscriptionId: DefaultContext.Subscription.Id,
153144
resourceGroupName: this.ResourceGroupName,
154145
resourceType: this.ResourceType,
155146
resourceName: this.ResourceName,

0 commit comments

Comments
 (0)