Skip to content

Commit f5fab2a

Browse files
committed
Merge pull request #94 from huangpf/clu
Clu
2 parents 84e685b + e870491 commit f5fab2a

File tree

85 files changed

+889
-289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+889
-289
lines changed

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
<Message Importance="high" Text="Running check in tests..." />
318318
<ItemGroup>
319319
<!--Exclude 1 test projects still in progress with build failures-->
320-
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json">
320+
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json" Exclude="$(CLURootDir)\Microsoft.CLU.Test\project.json">
321321
</_CLUTestProjects>
322322
</ItemGroup>
323323
<Exec Command="dnu build" WorkingDirectory="%(_CLUTestProjects.RootDir)%(_CLUTestProjects.Directory)" />

clu-getstart.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,36 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, you should se
7878

7979
```set CmdletSessionId=1010 ```
8080

81+
### Testing Cmdlets
82+
83+
#### Environment setup (Windows)
84+
- Install latest version of [Git for Windows](https://git-scm.com/download/win) that has `bash 4.x` available.
85+
- Install `jq` using chocolatey `choco install jq` (chocolatey can be installed from [here](https://chocolatey.org/)).
86+
87+
#### Test Infrastructure
88+
Testing will consist of scenario tests and unit tests. Scenario tests should be written in a form of an example and be available in `.ps1` and `.sh` formats.
89+
90+
#### Scenario Tests
91+
- Scenario tests should be saved under `./examples` directory and grouped by the package or service area. Each scenario tests should consist of both `.ps1` and `.sh` files and should cover "P0" scenarios.
92+
93+
##### Bash Tests
94+
- Bash tests should be runnable from bash shell in windows/linux/mac environments.
95+
- To manually run the tests; please set the following envt. variables for authentication and run `./examples/lib/testrunner.sh`
96+
```bash
97+
export azureuser=<[email protected]>
98+
export azurepassword=<your_password>
99+
export PATH=$PATH:/<path-to-drop>/clurun/win7-x64/
100+
. /examples/lib/testrunner.sh
101+
```
102+
- All the parameters to the cmdlets should be passed in as envt. variables
103+
- The current test runners will provide a unique resource group name via `$groupName` but may not remove it at the end if the test fails.
104+
- The location for ARM will be provided via variable `$location`.
105+
- "jq" package and BASH assert (e.g. `[ "foo" == "bar" ]`) should be used to validate the responses.
106+
107+
##### PowerShell Tests
108+
TODO: Add section on PowerShell testing
109+
110+
#### Unit Tests
111+
TODO: Add section on unit testing
112+
113+

examples/lib/helper.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
randomName() {
24
echo "$1$RANDOM"
35
}

examples/lib/setup.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#!/bin/bash
2-
32
# Login
4-
echo "Executing Login..."
5-
export CmdletSessionId=1010
6-
azure account add --username $azureuser --password $azurepassword
3+
login() {
4+
echo "Executing Login..."
5+
export CmdletSessionId=1010
6+
azure account add --username $azureuser --password $azurepassword
7+
}
8+
9+
cleanup() {
10+
set +e
11+
printf "\nCleanup: removing resource group: %s\n" $groupName
12+
azure group remove --name "$groupName" --force
13+
set -e
14+
}
15+
16+
export -f login
17+
export -f cleanup

examples/lib/testrunner.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#!/bin/bash
2-
. setup.sh
3-
. helper.sh
4-
export resourceGroupName=`randomName testrg`
5-
export resourceGroupLocation="westus"
2+
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3+
. $BASEDIR/assert.sh
4+
. $BASEDIR/helper.sh
5+
. $BASEDIR/setup.sh
6+
export groupName=`randomName testrg`
7+
export location="westus"
68

7-
for d in $( ls .. --ignore=lib ); do
8-
for f in $( ls ../$d/*.sh ); do
9+
login
10+
11+
for d in $( ls $BASEDIR/.. --ignore=lib ); do
12+
for f in $( ls $BASEDIR/../$d/*.sh ); do
913
echo "running: $f"
1014
. $f
15+
cleanup
16+
echo "success: $f"
1117
done
1218
done
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#!/bin/bash
2-
2+
set -e
33
printf "\n=== Managing Resource Groups in Azure ===\n"
44

5-
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$resourceGroupName" "$resourceGroupLocation"
6-
azure resource group new --name "$resourceGroupName" --location "$resourceGroupLocation"
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6+
azure group create --name "$groupName" --location "$location"
7+
8+
printf "\n2. Updating the group %s with tags.\n" "$groupName"
9+
azure group set --name "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
710

8-
printf "\n2. Updating the group %s with tags.\n" "$resourceGroupName"
9-
azure resource group set --name "$resourceGroupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
11+
printf "\n3. Get information about resource group : %s.\n" "$groupName"
12+
resourceGroupInfo=`azure group get --name $groupName`
1013

11-
printf "\n3. Get information about resource group : %s.\n" "$resourceGroupName"
12-
resourceGroupInfo=`azure resource group get --name $resourceGroupName`
13-
printf "\nThe resource group info is: \n %s\n" "$resourceGroupInfo"
14+
printf "\nValidating resource group name is: %s\n" "$groupName"
15+
[ $(echo $resourceGroupInfo | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
1416

1517
printf "\n4. Listing all resource groups in the subscription.\n"
16-
azure resource group get
18+
azure group get
1719

18-
printf "\n5. Removing resource group: %s.\n" "$resourceGroupName"
19-
azure resource group remove --name "$resourceGroupName" --force
20+
printf "\n5. Removing resource group: %s.\n" "$groupName"
21+
azure group remove --name "$groupName" --force

src/CLU/CLUCoreCLR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Run", "Micros
3737
EndProject
3838
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.CLU\Microsoft.CLU.xproj", "{D0A59671-088D-463B-B060-2ADAFFB9C3F6}"
3939
EndProject
40+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
41+
EndProject
4042
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}"
4143
ProjectSection(ProjectDependencies) = postProject
4244
{99B1290D-A073-4907-8018-51C714431778} = {99B1290D-A073-4907-8018-51C714431778}
@@ -127,6 +129,10 @@ Global
127129
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
128130
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
129131
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
130136
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131137
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
132138
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/CLU/Commands.Common.Authentication/Authentication/AdalTokenProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using Microsoft.Azure.Commands.Common.Authentication.Models;
1617
using System;
17-
using Commands.Common.Authentication.Properties;
1818

1919
namespace Microsoft.Azure.Commands.Common.Authentication
2020
{

src/CLU/Commands.Common.Authentication/Authentication/ServicePrincipalTokenProvider.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using Microsoft.Azure.Commands.Common.Authentication.Models;
1617
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1718
using Microsoft.Rest;
1819
using System;
19-
using System.Collections.Generic;
20-
using System.Security;
21-
using System.Security.Cryptography.X509Certificates;
22-
using Commands.Common.Authentication.Properties;
2320

2421
namespace Microsoft.Azure.Commands.Common.Authentication
2522
{

src/CLU/Commands.Common.Authentication/Authentication/UserTokenProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
using Microsoft.Rest;
1818
using System;
1919
using System.Runtime.InteropServices;
20-
using Commands.Common.Authentication.Properties;
2120
using Microsoft.Rest.Azure.Authentication;
2221
using System.Management.Automation;
22+
using Commands.Common.Authentication.Properties;
2323

2424
namespace Microsoft.Azure.Commands.Common.Authentication
2525
{

src/CLU/Commands.Common.Authentication/AuthenticationFactory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,11 +16,10 @@
1616
using System;
1717
using System.Linq;
1818
using System.Management.Automation;
19-
using System.Security;
20-
using Commands.Common.Authentication.Properties;
2119
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2220
using Microsoft.Rest;
2321
using Microsoft.Rest.Azure.Authentication;
22+
using Commands.Common.Authentication.Properties;
2423

2524
namespace Microsoft.Azure.Commands.Common.Authentication.Factories
2625
{

src/CLU/Commands.Common.Authentication/ClientFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using Microsoft.Azure.Commands.Common.Authentication.Models;
1617
using Microsoft.Rest;
1718
using System;
1819
using System.Collections.Generic;
1920
using System.Collections.Specialized;
20-
using System.Linq;
2121
using System.Management.Automation;
2222
using System.Net;
2323
using System.Net.Http;
2424
using System.Net.Http.Headers;
2525
using System.Reflection;
26-
using Commands.Common.Authentication.Properties;
2726

2827
namespace Microsoft.Azure.Commands.Common.Authentication.Factories
2928
{

src/CLU/Commands.Common.Authentication/JsonUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using Newtonsoft.Json;
1617
using Newtonsoft.Json.Linq;
1718
using System;
1819
using System.Collections.Generic;
1920
using System.Diagnostics.CodeAnalysis;
20-
using Commands.Common.Authentication.Properties;
2121

2222
namespace Microsoft.Azure.Commands.Common.Authentication
2323
{

src/CLU/Commands.Common.Authentication/Models/AzureEnvironment.Methods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using System;
1617
using System.Collections.Generic;
17-
using Commands.Common.Authentication.Properties;
1818

1919
namespace Microsoft.Azure.Commands.Common.Authentication.Models
2020
{
@@ -372,7 +372,7 @@ public static class AzureEnvironmentConstants
372372

373373
public const string USGovernmentSqlDatabaseDnsSuffix = ".database.usgovcloudapi.net";
374374

375-
public const string AzureActiveDirectoryEndpoint = "https://login.windows.net/";
375+
public const string AzureActiveDirectoryEndpoint = "https://login.microsoftonline.com/";
376376

377377
public const string ChinaActiveDirectoryEndpoint = "https://login.chinacloudapi.cn/";
378378

src/CLU/Commands.Common.Authentication/Models/AzureSMProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using Microsoft.Rest;
1617
using Newtonsoft.Json;
1718
using System;
1819
using System.Collections.Generic;
1920
using System.Linq;
20-
using Commands.Common.Authentication.Properties;
2121

2222
namespace Microsoft.Azure.Commands.Common.Authentication.Models
2323
{

src/CLU/Commands.Common.Authentication/Models/DiskDataStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using System;
1617
using System.IO;
1718
using System.Security.Cryptography.X509Certificates;
1819
using System.Text;
19-
using Commands.Common.Authentication.Properties;
2020

2121
namespace Microsoft.Azure.Commands.Common.Authentication.Models
2222
{

src/CLU/Commands.Common.Authentication/Properties/Resources.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CLU/Commands.Common.Authentication/Properties/Resources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@
120120
<data name="AccountNeedsToBeSpecified" xml:space="preserve">
121121
<value>Account needs to be specified</value>
122122
</data>
123-
<data name="AzureDirectoryName" xml:space="preserve">
124-
<value>Windows Azure Powershell</value>
125-
</data>
126123
<data name="CertificateNotFoundInStore" xml:space="preserve">
127124
<value>No certificate was found in the certificate store with thumbprint {0}</value>
128125
</data>

src/CLU/Commands.Common.Authentication/Validate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Commands.Common.Authentication.Properties;
1516
using System;
1617
using System.IO;
1718
using System.Linq;
18-
using Commands.Common.Authentication.Properties;
1919

2020
namespace Microsoft.Azure.Commands.Common.Authentication
2121
{

src/CLU/Commands.Common/AzurePSCmdlet.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,11 @@ protected virtual void WriteExceptionError(Exception ex)
436436
WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.CloseError, null));
437437
}
438438

439-
protected PSObject ConstructPSObject(string typeName, params object[] args)
439+
protected PSObject ConstructPSObject(params object[] args)
440440
{
441-
return PowerShellUtilities.ConstructPSObject(typeName, args);
441+
return PowerShellUtilities.ConstructPSObject(args);
442442
}
443-
444-
protected void SafeWriteOutputPSObject(string typeName, params object[] args)
445-
{
446-
PSObject customObject = this.ConstructPSObject(typeName, args);
447-
WriteObject(customObject);
448-
}
449-
443+
450444
private void FlushDebugMessages(bool record = false)
451445
{
452446
if (record)

src/CLU/Commands.Common/Models/PSAzureContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,14 @@ public static implicit operator AzureContext(PSAzureContext context)
8686
public PSAzureTenant Tenant { get; set; }
8787

8888
public byte[] TokenCache { get; set; }
89+
90+
public override string ToString()
91+
{
92+
var account = Account != null ? Account.Id : string.Empty;
93+
var subscription = Subscription != null ? Subscription.SubscriptionId : string.Empty;
94+
var tenant = Tenant != null ? Tenant.TenantId : string.Empty;
95+
var environment = Environment != null ? Environment.Name : EnvironmentName.AzureCloud;
96+
return $"{{Account: {account}, Subscription: {subscription}, Tenant: {tenant}, Environment: {environment}}}";
97+
}
8998
}
9099
}

src/CLU/Commands.Common/Models/PSAzureProfile.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public IDictionary<string, PSAzureEnvironment> Environments
6464
get { return _env; }
6565
}
6666

67+
public string EnvironmentNames
68+
{
69+
get { return _env == null? null : $"{string.Join(", ", _env.Keys.ToArray())}"; }
70+
}
71+
6772
/// <summary>
6873
/// The current credentials and metadata for connecting with the current Azure cloud instance.
6974
/// </summary>

src/CLU/Commands.Common/PowerShellUtilities.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,12 @@ private static void ChangeForTargetEnvironment(Func<IEnumerable<string>, IEnumer
5050
}
5151
}
5252

53-
public static PSObject ConstructPSObject(string typeName, params object[] args)
53+
public static PSObject ConstructPSObject(params object[] args)
5454
{
5555
Debug.Assert(args.Length % 2 == 0, "The parameter args length must be even number");
5656

5757
PSObject outputObject = new PSObject();
58-
59-
if (!string.IsNullOrEmpty(typeName))
60-
{
61-
outputObject.TypeNames.Add(typeName);
62-
}
63-
58+
6459
for (int i = 0, j = 0; i < args.Length / 2; i++, j += 2)
6560
{
6661
outputObject.Properties.Add(new PSNoteProperty(args[j].ToString(), args[j + 1]));

0 commit comments

Comments
 (0)