Skip to content

Commit 53aa8a7

Browse files
committed
Merge pull request #1 from markcowl/storageversions
Add script storage module to remove test setup dependencies on storage cmdlets
2 parents e16b662 + 6ad0a4c commit 53aa8a7

File tree

9 files changed

+134
-12
lines changed

9 files changed

+134
-12
lines changed

src/ResourceManager/ApiManagement/Commands.ApiManagement.Test/Commands.ApiManagement.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
</ProjectReference>
180180
</ItemGroup>
181181
<ItemGroup>
182+
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
183+
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
184+
</None>
182185
<None Include="packages.config">
183186
<SubType>Designer</SubType>
184187
</None>

src/ResourceManager/ApiManagement/Commands.ApiManagement.Test/ScenarioTests/ApiManagementTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ private void RunPowerShellTest(params string[] scripts)
176176
_helper.RMProfileModule,
177177
_helper.RMResourceModule,
178178
_helper.RMStorageDataPlaneModule,
179-
_helper.RMStorageModule,
180-
_helper.GetRMModulePath("AzureRM.ApiManagement.psd1"));
179+
_helper.GetRMModulePath("AzureRM.ApiManagement.psd1"),
180+
"AzureRM.Storage.ps1");
181181

182182
_helper.RunPowerShellTest(scripts);
183183
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
function Get-AzureRmStorageAccount
3+
{
4+
5+
[CmdletBinding()]
6+
param(
7+
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
8+
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
9+
BEGIN {
10+
$context = Get-Context
11+
$client = Get-StorageClient $context
12+
}
13+
PROCESS {
14+
$getTask = $client.StorageAccounts.GetPropertiesAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
15+
$sa = $getTask.Result
16+
$account = Get-StorageAccount $ResourceGroupName $Name
17+
Write-Output $account
18+
}
19+
END {}
20+
21+
}
22+
23+
function New-AzureRmStorageAccount
24+
{
25+
[CmdletBinding()]
26+
param(
27+
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
28+
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)][alias("StorageAccountName")] $Name,
29+
[string] [Parameter(Position=2, ValueFromPipelineByPropertyName=$true)] $Location,
30+
[string] [Parameter(Position=3, ValueFromPipelineByPropertyName=$true)] $Type)
31+
BEGIN {
32+
$context = Get-Context
33+
$client = Get-StorageClient $context
34+
}
35+
PROCESS {
36+
$createParms = New-Object -Type Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters
37+
$createParms.AccountType = [Microsoft.Azure.Management.Storage.Models.AccountType]::StandardLRS
38+
$createParms.Location = $Location
39+
$getTask = $client.StorageAccounts.CreateAsync($ResourceGroupName, $name, $createParms, [System.Threading.CancellationToken]::None)
40+
$sa = $getTask.Result
41+
}
42+
END {}
43+
44+
}
45+
46+
function Get-AzureRmStorageAccountKey
47+
{
48+
[CmdletBinding()]
49+
param(
50+
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
51+
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
52+
BEGIN {
53+
$context = Get-Context
54+
$client = Get-StorageClient $context
55+
}
56+
PROCESS {
57+
$getTask = $client.StorageAccounts.ListKeysAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
58+
Write-Output $getTask.Result.StorageAccountKeys
59+
}
60+
END {}
61+
}
62+
63+
function Remove-AzureRmStorageAccount
64+
{
65+
66+
[CmdletBinding()]
67+
param(
68+
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
69+
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
70+
BEGIN {
71+
$context = Get-Context
72+
$client = Get-StorageClient $context
73+
}
74+
PROCESS {
75+
$getTask = $client.StorageAccounts.DeleteAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
76+
$sa = $getTask.Result
77+
}
78+
END {}
79+
80+
}
81+
82+
function Get-Context
83+
{
84+
[Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext]$context = $null
85+
$profile = [Microsoft.WindowsAzure.Commands.Common.AzureRmProfileProvider]::Instance.Profile
86+
if ($profile -ne $null)
87+
{
88+
$context = $profile.Context
89+
}
90+
91+
return $context
92+
}
93+
94+
function Get-StorageClient
95+
{
96+
param([Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext] $context)
97+
$factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::ClientFactory
98+
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]
99+
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateClient", $types)
100+
$closedMethod = $method.MakeGenericMethod([Microsoft.Azure.Management.Storage.StorageManagementClient])
101+
$arguments = $context, [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]::ResourceManager
102+
$client = $closedMethod.Invoke($factory, $arguments)
103+
return $client
104+
}
105+
106+
function Get-StorageAccount {
107+
param([string] $resourceGroupName, [string] $name)
108+
$endpoints = New-Object PSObject -Property @{"Blob" = "https://$name.blob.core.windows.net/"}
109+
$sa = New-Object PSObject -Property @{"Name" = $name; "ResourceGroupName" = $resourceGroupName;
110+
"PrimaryEndpoints" = $endpoints
111+
}
112+
return $sa
113+
}

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Commands.ScenarioTests.ResourceManager.Common.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
<None Include="Assert.ps1">
162162
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
163163
</None>
164+
<None Include="AzureRM.Storage.ps1">
165+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
166+
</None>
164167
<None Include="Common.ps1">
165168
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
166169
</None>

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@
218218
<Link>ScenarioTests\Assert.ps1</Link>
219219
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
220220
</None>
221+
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
222+
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
223+
</None>
221224
<None Include="..\..\Resources\Commands.Resources.Test\ScenarioTests\Common.ps1">
222225
<Link>ScenarioTests\Common.ps1</Link>
223226
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public void RunPsTestWorkflow(
134134
helper.RMStorageDataPlaneModule,
135135
helper.RMStorageModule,
136136
helper.GetRMModulePath("AzureRM.Compute.psd1"),
137-
helper.GetRMModulePath("AzureRM.Network.psd1"));
137+
helper.GetRMModulePath("AzureRM.Network.psd1"),
138+
"AzureRM.Storage.ps1");
138139

139140
try
140141
{

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/SqlTestsBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ protected void RunPowerShellTest(params string[] scripts)
8484
"ScenarioTests\\" + this.GetType().Name + ".ps1",
8585
helper.RMProfileModule,
8686
helper.RMResourceModule,
87-
helper.RMStorageDataPlaneModule,
88-
helper.RMStorageModule,
87+
helper.RMStorageDataPlaneModule,
8988
helper.GetRMModulePath(@"AzureRM.Insights.psd1"),
90-
helper.GetRMModulePath(@"AzureRM.Sql.psd1"));
89+
helper.GetRMModulePath(@"AzureRM.Sql.psd1"),
90+
"AzureRM.Storage.ps1");
9191
helper.RunPowerShellTest(scripts);
9292
}
9393
}

src/ResourceManager/Websites/Commands.Websites.Test/Commands.Websites.Test.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
<Compile Include="Properties\AssemblyInfo.cs" />
153153
</ItemGroup>
154154
<ItemGroup>
155+
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
156+
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
157+
</None>
155158
<None Include="MSSharedLibKey.snk" />
156159
<None Include="packages.config">
157160
<SubType>Designer</SubType>
@@ -304,10 +307,6 @@
304307
<Project>{e1f5201d-6067-430e-b303-4e367652991b}</Project>
305308
<Name>Commands.Resources</Name>
306309
</ProjectReference>
307-
<ProjectReference Include="..\..\Storage\Commands.Management.Storage\Commands.Management.Storage.csproj">
308-
<Project>{a50ab133-5c04-4a17-9054-f8343683ec23}</Project>
309-
<Name>Commands.Management.Storage</Name>
310-
</ProjectReference>
311310
<ProjectReference Include="..\Commands.Websites\Commands.Websites.csproj">
312311
<Project>{80a92297-7c92-456b-8ee7-9fb6ce30149d}</Project>
313312
<Name>Commands.Websites</Name>

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebsitesController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ public void RunPsTestWorkflow(
117117
"ScenarioTests\\" + callingClassName + ".ps1",
118118
helper.RMProfileModule,
119119
helper.RMStorageDataPlaneModule,
120-
helper.RMStorageModule,
121120
helper.RMResourceModule,
122-
helper.GetRMModulePath(@"AzureRM.WebSites.psd1"));
121+
helper.GetRMModulePath(@"AzureRM.WebSites.psd1"),
122+
"AzureRM.Storage.ps1");
123123

124124
try
125125
{

0 commit comments

Comments
 (0)