Skip to content

Commit

Permalink
Apply Suggestion and fix preview sort
Browse files Browse the repository at this point in the history
  • Loading branch information
gotit96 committed Oct 30, 2023
1 parent 4c99390 commit 845b87c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/Public/Get-SqlDscPreferredModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function Get-SqlDscPreferredModule
{
# Get the latest version if available
$availableModule = $preferredModules |
Sort-Object -Property { ($_.CalculatedVersion -replace '-.+$') -as [version] }, { $_ } -Descending |
Sort-Object -Property { ($_.CalculatedVersion -replace '-.+$') -as [System.Version] }, { $_.CalculatedVersion } -Descending |
Select-Object -First 1
}

Expand Down
12 changes: 11 additions & 1 deletion tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' {
}
}
}
$sqlServerModule3 = New-MockObject -Type 'PSModuleInfo' -Properties @{
Name = 'SqlServer'
Version = [Version]::new(22, 1, 1)
PrivateData = @{
PSData = @{
PreRelease = 'preview2'
}
}
}
$sqlpsModule1 = New-MockObject -Type 'PSModuleInfo' -Properties @{
Name = 'SQLPS'
Path = 'C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\SQLPS\Sqlps.ps1'
Expand All @@ -381,14 +390,15 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' {
return @(
$sqlServerModule1,
$sqlServerModule2,
$sqlServerModule3,
$sqlpsModule1,
$sqlpsModule2
)
}
}

It 'Should return the latest first preferred module' {
Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule2
Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule3
}

Context 'When the environment variable SMODefaultModuleVersion is assigned a module version' {
Expand Down

0 comments on commit 845b87c

Please sign in to comment.