Skip to content

Commit e056251

Browse files
committed
Merge pull request Azure#282 from Azure/clu
Clu
2 parents 6866f6b + 028d61f commit e056251

File tree

14 files changed

+83
-47
lines changed

14 files changed

+83
-47
lines changed

clu-getstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ Testing will consist of scenario tests and unit tests. Scenario tests should be
118118
```
119119
- Set the environment variable 'TestCredentials' to a connection string providing the credentials to use during test execution. Possible fields include:
120120

121-
| Field | Description |
121+
| Field (case sensitive) | Description |
122122
| ------------- |:-------------|
123123
| Username | an OrgId user name |
124124
| ServicePrincipal | a service principal name |
125125
| Password | the password or application secret to sue for authentication |
126126
| TenantId | (required for Service authentication) The tenant guid to authenticate against |
127-
| SubscriptionID | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
127+
| SubscriptionId | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
128128
- The infrastructure automatically generates a resource group name and assigns the value to the bash variable ```"$resourceGroupName"```. If your scripts require additional variables, you can add these to your environment before running tests, or you can generate values using the ScriptRunner (for the tests using that runner).
129129
```C#
130130
runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));

examples/lib/setup.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/lib/testrunner.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
#!/bin/bash
22
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3-
. $BASEDIR/assert.sh
43
. $BASEDIR/helper.sh
5-
. $BASEDIR/setup.sh
64
export groupName=`randomName testrg`
75
export location="westus"
6+
export CmdletSessionID=1010
7+
export MSYS_NO_PATHCONV=1
88

9-
login
9+
echo "Logging in as user"
10+
. $BASEDIR/loginUser.sh
1011

1112
for d in $( ls $BASEDIR/.. --ignore=lib ); do
1213
for f in $( ls $BASEDIR/../$d/*.sh ); do
1314
echo "running: $f"
1415
. $f
15-
cleanup
16+
set +e
17+
printf "\nCleanup: removing resource group: %s\n" $groupName
18+
azure group remove --name "$groupName" --force
19+
set -e
1620
echo "success: $f"
1721
done
18-
done
22+
done
23+
24+
export MSYS_NO_PATHCONV=

src/CLU/Commands.Common.ScenarioTest/EnvironmentCredentialsProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ protected virtual IDictionary<string, string> GetSettings(string key)
4545
var environmentValue = Environment.GetEnvironmentVariable(key);
4646
if (string.IsNullOrWhiteSpace(environmentValue))
4747
{
48-
throw new InvalidOperationException($"Unable to create credentials. " +
49-
"Please set environment ${key}");
48+
throw new InvalidOperationException($"Unable to create credentials. Please set environment variable `{key}`");
5049
}
5150
IDictionary<string, string> settings = new Dictionary<string, string>();
5251
foreach (

src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ public class ExampleScriptRunner
3939
ResourceManagementClient _client;
4040
const string DefaultLocation = "westus";
4141
const string ResourceGroupNameKey = "groupName";
42-
const string locationKey = "location";
42+
const string LocationKey = "location";
43+
const string BaseDir = "BASEDIR";
4344
const string SessionKey = "CmdletSessionID";
44-
const string storageAccountTypeKey = "storageAccountType";
45-
const string storageAccountNameKey = "storageAccountName";
45+
const string StorageAccountTypeKey = "storageAccountType";
46+
const string StorageAccountNameKey = "storageAccountName";
4647
const string DefaultStorageAccountType = "Standard_GRS";
4748

4849
public ExampleScriptRunner(string sessionId) : this(new Random(), sessionId)
@@ -106,11 +107,12 @@ public string RunScript(string testName)
106107
DeployTemplate(deploymentTemplatePath, _resourceGroupName);
107108
}
108109

110+
process.EnvironmentVariables[BaseDir] = testDirectory;
109111
process.EnvironmentVariables[SessionKey] = _sessionId;
110112
process.EnvironmentVariables[ResourceGroupNameKey] = _resourceGroupName;
111-
process.EnvironmentVariables[locationKey] = DefaultLocation;
112-
process.EnvironmentVariables[storageAccountTypeKey] = DefaultStorageAccountType;
113-
process.EnvironmentVariables[storageAccountNameKey] = _storageAccountName;
113+
process.EnvironmentVariables[LocationKey] = DefaultLocation;
114+
process.EnvironmentVariables[StorageAccountTypeKey] = DefaultStorageAccountType;
115+
process.EnvironmentVariables[StorageAccountNameKey] = _storageAccountName;
114116
foreach (var helper in _context.EnvironmentHelpers)
115117
{
116118
helper.TrySetupScriptEnvironment(_context, _clientFactory, process.EnvironmentVariables);

src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,16 @@ private void SetEnvironmentVariables(ProcessStartInfo startInfo)
173173

174174
private void ProcessError(object sender, DataReceivedEventArgs e)
175175
{
176-
Logger.Instance.WriteError(e.Data);
176+
if (e.Data != null)
177+
{
178+
Logger.Instance.WriteError(e.Data);
179+
}
177180
}
178181

179182
private void ProcessOutput(object sender, DataReceivedEventArgs e)
180183
{
181-
Logger.Instance.WriteMessage(e.Data);
182184
_processOutput.Append(e.Data);
185+
Logger.Instance.WriteMessage(e.Data);
183186
}
184187

185188
private void EndProcess()

src/CLU/Commands.Common.ScenarioTest/SampleTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public SampleTest(ScenarioTestFixture fixture)
3333
}
3434

3535
[Fact]
36-
public void RunSampleTest()
36+
public void ResourceGroupsTest()
3737
{
3838
var helper = _collectionState.GetRunner("resource-management");
3939
helper.RunScript("01-ResourceGroups");
4040
}
4141

4242
[Fact]
43-
public void RunVirtualHardDiskTest()
43+
public void VirtualHardDisksTest()
4444
{
4545
var helper = _collectionState.GetRunner("virtual-hard-disk");
4646
helper.RunScript("01-VirtualHardDisks");

src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.Azure.Commands.Common.Authentication.Models;
1717
using Microsoft.Azure.Commands.Common.ScenarioTest;
1818
using Microsoft.Azure.Commands.Models;
19-
using Moq.Protected;
2019
using Newtonsoft.Json;
2120

2221
namespace Microsoft.Azure.Commands.Common.ScenarioTest
@@ -34,6 +33,10 @@ public ScenarioTestFixture()
3433
var helper = GetRunner("lib");
3534
var profileText = helper.RunScript(credentials.LoginScriptName);
3635
var profile = JsonConvert.DeserializeObject<PSAzureProfile>(profileText);
36+
if (profile == null)
37+
{
38+
throw new ArgumentOutOfRangeException(nameof(profile), $"Deserialized profile is null: `{profileText}`");
39+
}
3740
AzureContext = (AzureContext) (profile.Context);
3841
}
3942

src/CLU/Commands.Common.ScenarioTest/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"Commands.Common": "",
2121
"Commands.Common.Authentication": "",
2222
"Commands.ResourceManager.Common": "",
23-
"Commands.ScenarioTests.ResourceManager.Common": "",
2423
"Microsoft.Azure.Commands.Profile": "",
2524
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
2625
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",

src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void WriteProgress(long sourceId, ProgressRecord record)
6363
{
6464
if (record == null)
6565
{
66-
Console.CursorVisible = true;
6766
throw new ArgumentNullException("record");
6867
}
6968

@@ -80,14 +79,12 @@ public void WriteProgress(long sourceId, ProgressRecord record)
8079
_console.Write(" ");
8180
}
8281
_console.WriteLine();
83-
Console.CursorVisible = true;
8482
}
8583
else
8684
{
87-
Console.CursorVisible = false;
8885
var statusLine = string.Format(Strings.ConsoleDataStream_WriteProgress_StatusLineInProgress, record.Activity, record.StatusDescription, record.CurrentOperation, record.SecondsRemaining);
8986
// Subtract what's already known to be needed:
90-
width -= statusLine.Length + 3;
87+
width = Math.Max(1, width - (statusLine.Length + 3));
9188

9289
var chunkSize = (100 / width) + 1;
9390

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
using System.Management.Automation;
7+
8+
namespace Microsoft.CLU.Test
9+
{
10+
11+
[Cmdlet(VerbsCommon.Show, "Progress")]
12+
public class ShowProgress: PSCmdlet
13+
{
14+
[Parameter()]
15+
public int Steps{ get; set; }
16+
17+
18+
protected override void ProcessRecord()
19+
{
20+
base.ProcessRecord();
21+
22+
var progRecord = new ProgressRecord(4711, "Testing progress", "Running");
23+
WriteProgress(progRecord);
24+
for (int step = 1; step <= Steps; ++step)
25+
{
26+
System.Threading.Thread.Sleep(100);
27+
progRecord.PercentComplete = step * 100 / Steps;
28+
WriteProgress(progRecord);
29+
}
30+
progRecord.RecordType = ProgressRecordType.Completed;
31+
WriteProgress(progRecord);
32+
}
33+
}
34+
}

src/CLU/Microsoft.ScenarioTests.CLU/project.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"dependencies": {
1111
"Microsoft.NETCore": "5.0.1-beta-23516",
1212
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
13-
"Microsoft.CSharp": "4.0.1-beta-23516"
13+
"Microsoft.CSharp": "4.0.1-beta-23516",
14+
15+
"System.Threading.Thread": "4.0.0-beta-23516"
1416
}
1517
}
1618
},

tools/CLU/BuildAndInstallClu.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ copy /Y %root%\drop\clurun\win7-x64\azure.lx %root%\drop\clurun\osx.10.10-x64
4242
copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\osx.10.10-x64
4343

4444
REM: copy over the pre-cooked azure.sh and ensure correct line endings
45-
copy /Y %~dp0\azure.sh %root%\drop\clurun\osx.10.10-x64
46-
set azuresh=%root%\drop\clurun\osx.10.10-x64\azure.sh
45+
copy /Y %~dp0\azure.sh %root%\drop\clurun\osx.10.10-x64\azure
46+
set azuresh=%root%\drop\clurun\osx.10.10-x64\azure
4747
echo Get-ChildItem %azuresh% ^| ForEach-Object { > %temp%\fixLineEndings.ps1
4848
echo $contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n" >> %temp%\fixLineEndings.ps1
4949
echo [IO.File]::WriteAllText($_, $contents) >> %temp%\fixLineEndings.ps1
@@ -53,7 +53,7 @@ echo } >> %temp%\fixLineEndings.ps1
5353
xcopy %root%\drop\clurun\win7-x64\pkgs %root%\drop\clurun\ubuntu.14.04-x64\pkgs /S /Q /I /Y
5454
copy /Y %root%\drop\clurun\win7-x64\azure.lx %root%\drop\clurun\ubuntu.14.04-x64
5555
copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\ubuntu.14.04-x64
56-
copy /Y %azuresh% %root%\drop\clurun\ubuntu.14.04-x64
56+
copy /Y %azuresh% %root%\drop\clurun\ubuntu.14.04-x64\azure
5757

5858
REM, windows version also needs it for bash based testing
59-
copy /Y %azuresh% %root%\drop\clurun\win7-x64\azure
59+
copy /Y %~dp0\azure.win.sh %root%\drop\clurun\win7-x64\azure

tools/CLU/azure.win.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
if [ -z ${CmdletSessionID} ]
3+
then
4+
export CmdletSessionID=$PPID
5+
fi
6+
SCRIPTPATH=$(dirname "$0")
7+
WSCRIPTPATH=$({ cd $SCRIPTPATH && pwd -W; } | sed 's|/|\\|g')
8+
$WSCRIPTPATH/clurun -s azure -r $WSCRIPTPATH/azure.lx "$@"

0 commit comments

Comments
 (0)