-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlServerDsc: fix sort in SqlDscPreferredModule to get the latest version #1976
SqlServerDsc: fix sort in SqlDscPreferredModule to get the latest version #1976
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1976 +/- ##
====================================
Coverage 92% 92%
====================================
Files 93 93
Lines 7840 7840
====================================
Hits 7214 7214
Misses 626 626
|
I will try to get to this as soon as possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @gotit96)
source/Public/Get-SqlDscPreferredModule.ps1
line 121 at r2 (raw file):
# Get the latest version if available $availableModule = $preferredModules | Sort-Object -Property { ($_.CalculatedVersion -replace '-.+$') -as [version] }, { $_ } -Descending |
Change to the full type name.
Suggestion:
[System.Version]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @gotit96)
tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1
line 392 at r2 (raw file):
It 'Should return the latest first preferred module' { Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule2 }
This change does not seem to return the correct preview versions if several are available. If adding this test it will fail with the proposed, but it will pass when not using the proposed change.
Suggestion:
BeforeAll {
$sqlServerModule1 = New-MockObject -Type 'PSModuleInfo' -Properties @{
Name = 'SqlServer'
Version = [Version]::new(21, 1, 18068)
}
$sqlServerModule2 = New-MockObject -Type 'PSModuleInfo' -Properties @{
Name = 'SqlServer'
Version = [Version]::new(22, 1, 1)
PrivateData = @{
PSData = @{
PreRelease = 'preview1'
}
}
}
$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'
}
$sqlpsModule2 = New-MockObject -Type 'PSModuleInfo' -Properties @{
Name = 'SQLPS'
Path = 'C:\Program Files (x86)\Microsoft SQL Server\160\Tools\PowerShell\Modules\SQLPS\Sqlps.ps1'
}
Mock -CommandName Get-Module -MockWith {
return @(
$sqlServerModule1,
$sqlServerModule2,
$sqlServerModule3,
$sqlpsModule1,
$sqlpsModule2
)
}
}
It 'Should return the latest first preferred module' {
Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule3
}
fixed |
Test added, and sort of preview version fixed. digging deeper into the test, it seems that powershell does not allow the installation of multiple prerelease/releases of the same version: > Install-Module -Name dbatools -RequiredVersion 2.0.0-preview2 -AllowPrerelease
> Get-Module -Name dbatools -ListAvailable | Select-Object -Property Name,Version,{$_.PrivateData.PSData.Prerelease}
Name Version $_.PrivateData.PSData.Prerelease
---- ------- --------------------------------
dbatools 2.0.0 preview2
dbatools 1.1.146
> Install-Module -Name dbatools -RequiredVersion 2.0.0-preview5 -AllowPrerelease
> Get-Module -Name dbatools -ListAvailable | Select-Object -Property Name,Version,{$_.PrivateData.PSData.Prerelease}
Name Version $_.PrivateData.PSData.Prerelease
---- ------- --------------------------------
dbatools 2.0.0 preview5
dbatools 1.1.146
> Install-Module -Name dbatools -RequiredVersion 2.0.0
WARNING : Version '2.0.0' of module 'dbatools' is already installed at '...\dbatools\2.0.0'. To reinstall this version '2.0.0', run Install-Module or
Updated-Module cmdlet with the -Force parameter.
> Install-Module -Name dbatools -RequiredVersion 2.0.0 -Force
> Get-Module -Name dbatools -ListAvailable | Select-Object -Property Name,Version,{$_.PrivateData.PSData.Prerelease}
Name Version $_.PrivateData.PSData.Prerelease
---- ------- --------------------------------
dbatools 2.0.0
dbatools 1.1.146
|
Yes, but you can have modules installed in different folders that are part of PS> Get-Module -Name dbatools -ListAvailable | Select-Object -Property Name,Version,{$_.PrivateData.PSData.Prerelease}
Name Version $_.PrivateData.PSData.Prerelease
---- ------- --------------------------------
dbatools 2.0.0 preview2
dbatools 2.0.0 preview5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @gotit96)
Pull Request (PR) description
Get-SMOModuleCalculatedVersion
Get-SqlDscPreferredModule
This Pull Request (PR) fixes the following issues
With multiple version of SqlServer installed:
Get-SqlDscPreferredModule was selecting:
This proposed change update the sort to get the latest version;
Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
This change is