Skip to content

Commit

Permalink
Add tests on Profile module version check
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Sep 29, 2015
1 parent f0d6618 commit cf9d854
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ResourceManager/Profile/CheckVersions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ $AzureRMModules = @(
"AzureRM.Websites"
)

$AvailableModules = @()

function CheckVersions {
$profile = GetModuleInfo("AzureRM.Profile")
if (-not $profile)
Expand All @@ -48,7 +50,12 @@ function GetModuleInfo {
[string]
$ModuleName)

return Get-Module -ListAvailable `
if ($global:AvailableModules.Length -eq 0)
{
$global:AvailableModules = Get-Module -ListAvailable
}

return $global:AvailableModules `
| Where-Object { $_.Name -eq $ModuleName} `
| Select-Object -first 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<Compile Include="EnvironmentCmdletTests.cs" />
<Compile Include="MockSubscriptionClientFactory.cs" />
<Compile Include="ProfileController.cs" />
<Compile Include="ProfileModuleTests.cs" />
<Compile Include="SubscriptionCmdletTests.cs" />
<Compile Include="TenantCmdletTests.cs" />
<Compile Include="LoginCmdletTests.cs" />
Expand All @@ -193,9 +194,18 @@
</Content>
<None Include="MSSharedLibKey.snk" />
<None Include="packages.config" />
<None Include="ProfileModuleTestRepo\AzureRM.ApiManagement.998.9.8.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ProfileModuleTestRepo\AzureRM.Profile.999.9.8.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests\AllParameterSetsSucceed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="ProfileModuleTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Resources.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.Profile.Test
{
public class ProfileModuleTests
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void WarningOnIncompatibleVersions()
{
ProfileController.NewInstance.RunPsTest("db1ab6f0-4769-4b27-930e-01e2ef9c123c", "Test-LoadProfileModule");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests each of the major parts of retrieving subscriptions in ARM mode
#>
function Test-LoadProfileModule
{
$buffer = ""
try {
Register-PSRepository -Name "ProfileModuleTest" -SourceLocation (Resolve-Path .\).Path -InstallationPolicy Trusted
Write-Warning "Point 1"
try {
Install-Module AzureRM.ApiManagement -Scope CurrentUser -Repository ProfileModuleTest -RequiredVersion 998.9.8
Write-Warning "Point 2"
$buffer = Import-Module AzureRM.Profile 2>&1 3>&1 | Out-String
Write-Warning "Point 2.5"
Write-Warning $buffer
} finally {
Write-Warning "Point 3"
Uninstall-Module AzureRM.ApiManagement -ErrorAction Ignore
Uninstall-Module AzureRM.Profile -ErrorAction Ignore
Write-Warning "Point 4"
}
} finally {
Write-Warning "Point 5"
Unregister-PSRepository -Name "ProfileModuleTest"
}
Assert-True { $buffer -Like "*AzureRM.ApiManagement 998.9.8 is not compatible with AzureRM.Profile*" }
}

0 comments on commit cf9d854

Please sign in to comment.