Skip to content

Commit 240c89e

Browse files
committed
Merge pull request #1501 from stankovski/clu
Added documentation for bash testing and created basic BASH test infrastructure
2 parents 2db5c9e + e6ca066 commit 240c89e

File tree

7 files changed

+82
-22
lines changed

7 files changed

+82
-22
lines changed

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

tools/CLU/BuildAndInstallClu.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ copy /Y %~dp0\azure.sh %root%\drop\clurun\osx.10.10-x64
3333
xcopy %root%\drop\clurun\win7-x64\pkgs %root%\drop\clurun\ubuntu.14.04-x64\pkgs /S /Q /I /Y
3434
copy /Y %root%\drop\clurun\win7-x64\azure.lx %root%\drop\clurun\ubuntu.14.04-x64
3535
copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\ubuntu.14.04-x64
36-
copy /Y %~dp0\azure.sh %root%\drop\clurun\ubuntu.14.04-x64
36+
copy /Y %~dp0\azure.sh %root%\drop\clurun\ubuntu.14.04-x64
37+
38+
copy /Y %~dp0\azure %root%\drop\clurun\win7-x64

tools/CLU/azure

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
BASEDIR=$(dirname $0)
3+
4+
clurun.exe -s azure -r $BASEDIR/azure.lx $*

0 commit comments

Comments
 (0)