Skip to content

Commit 10e95d3

Browse files
authored
Update azmodule test for version (#68)
# Pull Request ## Description Description of changes: Updated Az module tests to check for a specific version of at least 10.0.0. ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
1 parent d12c1b6 commit 10e95d3

File tree

5 files changed

+49
-32
lines changed

5 files changed

+49
-32
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Test-ALZRequirement
4040

4141
Currently this tests for:
4242

43-
* Supported minimum PowerShell version
44-
* Azure PowerShell Module
43+
* Supported minimum PowerShell version (7.1)
44+
* Supported minimum Az PowerShell module version (10.0.0)
4545
* Git
4646
* Azure CLI
4747
* Bicep

src/ALZ/Private/Test-Utility-Functions.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
function Get-PSVersion { $PSVersionTable }
33

44
#Unable to mock $PSScriptRoot variable
5-
function Get-ScriptRoot { $PSScriptRoot }
5+
function Get-ScriptRoot { $PSScriptRoot }
6+
7+
# Used to allow mocking of the Get-Module AZ
8+
function Get-AZVersion { Get-Module -Name Az -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 }

src/ALZ/Public/Test-ALZRequirement.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ function Test-ALZRequirement {
8585
Write-Error "Bicep is not installed. Please install Bicep."
8686
$result = $false
8787
}
88-
# Check if Azure PowerShell module is installed
89-
$azModule = Get-Module -Name Az -ListAvailable
90-
if ($azModule) {
91-
Write-Verbose "Azure PowerShell module is installed."
92-
} else {
93-
Write-Error "Azure PowerShell module is not installed. Please install the Azure PowerShell module."
88+
# Check if AZ PowerShell module is the correct version
89+
$azModule = Get-AZVersion
90+
if ($azModule.Version.Major -lt 10) {
91+
Write-Error "Az module version $($azModule.Version) is not supported. Please Upgrade to AZ module version 10.0.0 or higher."
9492
$result = $false
93+
} else {
94+
Write-Verbose "Az module version is supported."
9595
}
9696
if ($result) {
9797
return "ALZ requirements are met."

src/Tests/Unit/Private/Test-ALZRequirement.Tests.ps1

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,27 @@ Import-Module $PathToManifest -Force
1212
#-------------------------------------------------------------------------
1313

1414
InModuleScope 'ALZ' {
15-
Describe 'Request-ConfigurationValue Public Function Tests' -Tag Unit {
15+
Describe 'Test-ALZRequirement Public Function Tests' -Tag Unit {
1616
BeforeAll {
1717
$WarningPreference = 'SilentlyContinue'
1818
$ErrorActionPreference = 'SilentlyContinue'
1919
}
20-
Context 'Non Az Module' {
20+
Context 'Incompatible Az module version lower than 10.0.0' {
2121
BeforeEach {
22-
Mock -CommandName Get-Module -MockWith {
23-
$null
22+
Mock -CommandName Get-AZVersion -MockWith {
23+
[PSCustomObject]@{
24+
Version = [PSCustomObject]@{
25+
Major = 9
26+
Minor = 7
27+
}
28+
}
2429
}
2530
}
26-
It 'should return the not met for non AZ module' {
31+
It 'should return the not met for non compatible az module versions' {
2732
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
2833
}
2934
}
30-
Context 'Incompatible Powershell version lower them 7' {
35+
Context 'Incompatible Powershell version lower than 7' {
3136
BeforeEach {
3237
Mock -CommandName Get-PSVersion -MockWith {
3338
[PSCustomObject]@{
@@ -63,7 +68,7 @@ InModuleScope 'ALZ' {
6368
$null
6469
}
6570
}
66-
It 'should return the not met for no git instalation' {
71+
It 'should return the not met for no git installation' {
6772
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
6873
}
6974
}
@@ -73,7 +78,7 @@ InModuleScope 'ALZ' {
7378
$null
7479
}
7580
}
76-
It 'should return the not met for no Visual Studio Code instalation' {
81+
It 'should return the not met for no Visual Studio Code installation' {
7782
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
7883
}
7984
}
@@ -83,16 +88,18 @@ InModuleScope 'ALZ' {
8388
$null
8489
}
8590
}
86-
It 'should return the not met for no bicep instalation' {
91+
It 'should return the not met for no bicep installation' {
8792
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
8893
}
8994
}
9095
Context 'Success' {
91-
9296
BeforeEach {
93-
Mock -CommandName Get-Module -MockWith {
97+
Mock -CommandName Get-AZVersion -MockWith {
9498
[PSCustomObject]@{
95-
Name = 'Az'
99+
Version = [PSCustomObject]@{
100+
Major = 10
101+
Minor = 0
102+
}
96103
}
97104
}
98105
Mock -CommandName Get-PSVersion -MockWith {
@@ -123,7 +130,6 @@ InModuleScope 'ALZ' {
123130
It 'should return the expected results' {
124131
Test-ALZRequirement | Should -BeExactly "ALZ requirements are met."
125132
}
126-
127133
}
128134
}
129135
}

src/Tests/Unit/Public/Test-ALZRequirement.Tests.ps1

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ InModuleScope 'ALZ' {
1717
$WarningPreference = 'SilentlyContinue'
1818
$ErrorActionPreference = 'SilentlyContinue'
1919
}
20-
Context 'Non Az Module' {
20+
Context 'Incompatible Az module version lower than 10.0.0' {
2121
BeforeEach {
22-
Mock -CommandName Get-Module -MockWith {
23-
$null
22+
Mock -CommandName Get-AZVersion -MockWith {
23+
[PSCustomObject]@{
24+
Version = [PSCustomObject]@{
25+
Major = 9
26+
Minor = 7
27+
}
28+
}
2429
}
2530
}
26-
It 'should return the not met for non AZ module' {
31+
It 'should return the not met for non compatible az module versions' {
2732
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
2833
}
2934
}
30-
Context 'Incompatible Powershell version lower them 7' {
35+
Context 'Incompatible Powershell version lower than 7' {
3136
BeforeEach {
3237
Mock -CommandName Get-PSVersion -MockWith {
3338
[PSCustomObject]@{
@@ -63,7 +68,7 @@ InModuleScope 'ALZ' {
6368
$null
6469
}
6570
}
66-
It 'should return the not met for no git instalation' {
71+
It 'should return the not met for no git installation' {
6772
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
6873
}
6974
}
@@ -73,7 +78,7 @@ InModuleScope 'ALZ' {
7378
$null
7479
}
7580
}
76-
It 'should return the not met for no Visual Studio Code instalation' {
81+
It 'should return the not met for no Visual Studio Code installation' {
7782
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
7883
}
7984
}
@@ -83,15 +88,18 @@ InModuleScope 'ALZ' {
8388
$null
8489
}
8590
}
86-
It 'should return the not met for no bicep instalation' {
91+
It 'should return the not met for no bicep installation' {
8792
Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met."
8893
}
8994
}
9095
Context 'Success' {
9196
BeforeEach {
92-
Mock -CommandName Get-Module -MockWith {
97+
Mock -CommandName Get-AZVersion -MockWith {
9398
[PSCustomObject]@{
94-
Name = 'Az'
99+
Version = [PSCustomObject]@{
100+
Major = 10
101+
Minor = 0
102+
}
95103
}
96104
}
97105
Mock -CommandName Get-PSVersion -MockWith {

0 commit comments

Comments
 (0)