Skip to content

Commit

Permalink
Import-SqlDscPreferredModule: Allow unit tests to run cross-plattfo…
Browse files Browse the repository at this point in the history
…rm (#1852)

- `Import-SqlDscPreferredModule`
  - No longer tries to get the environment variables from the machine state
    when run on Linux or macOS. This will allow the unit tests to run
    cross-plattform.
  • Loading branch information
johlju authored Feb 12, 2023
1 parent 49cf40c commit ea2a62a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Uninstall-SqlDscServer`
- Was changed to support the SQL Server 2022 GA feature `AzureExtension`
(that replaced the feature name `ARC`) ([issue #1798](https://github.com/dsccommunity/SqlServerDsc/issues/1798)).
- `Import-SqlDscPreferredModule`
- No longer tries to get the environment variables from the machine state
when run on Linux or macOS. This will allow the unit tests to run
cross-plattform.
- SqlReplication
- The resource now supports SQL Server 2022. The resource will require
the module _SqlServer_ v22.0.49-preview or newer when used against an
Expand Down
18 changes: 11 additions & 7 deletions source/Public/Import-SqlDscPreferredModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ function Import-SqlDscPreferredModule
{
Write-Verbose -Message ($script:localizedData.PreferredModule_ModuleNotFound)

<#
After installing SQL Server the current PowerShell session doesn't know
about the new path that was added for the SQLPS module. This reloads
PowerShell session environment variable PSModulePath to make sure it
contains all paths.
#>
Set-PSModulePath -Path ([System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine'))
# Only run on Windows that has Machine state.
if (-not ($IsLinux -or $IsMacOS))
{
<#
After installing SQL Server the current PowerShell session doesn't know
about the new path that was added for the SQLPS module. This reloads
PowerShell session environment variable PSModulePath to make sure it
contains all paths.
#>
Set-PSModulePath -Path ([System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine'))
}

# Get the newest SQLPS module if more than one exist.
$availableModule = Get-Module -FullyQualifiedName 'SQLPS' -ListAvailable |
Expand Down

0 comments on commit ea2a62a

Please sign in to comment.