diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f3cce6d2..bbcbe6902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SqlDatabaseObjectPermission - New integration tests to verify scenarios when passing a single permission. +### Changed + +- SqlServerDsc + - Minor document changes in the file `build.yml`. +- SqlSetup + - Duplicate function Get-SqlMajorVersion was removed and instead the + helper function `Get-FilePathMajorVersion` from the helper module + SqlServerDsc.Common is used ([issue #1178](https://github.com/PowerShell/SqlServerDsc/issues/1178)). +- SqlWindowsFirewall + - Duplicate function Get-SqlMajorVersion was removed and instead the + helper function `Get-FilePathMajorVersion` from the helper module + SqlServerDsc.Common is used ([issue #1178](https://github.com/PowerShell/SqlServerDsc/issues/1178)). +- SqlServerDsc.Common + - Function `Get-FilePathMajorVersion` was added. The function `Get-SqlMajorVersion` + from the resources _SqlSetup_ and _SqlWindowsFirewall_ was moved and + renamed without any functional changes ([issue #1178](https://github.com/PowerShell/SqlServerDsc/issues/1178)). + ### Fixed - SqlServerDsc diff --git a/build.yaml b/build.yaml index d698a97ce..0edf7e693 100644 --- a/build.yaml +++ b/build.yaml @@ -1,6 +1,38 @@ --- #################################################### -# ModuleBuilder Configuration # +# Pipeline Build Task Configuration (Invoke-Build) # +#################################################### +BuildWorkflow: + '.': + - build + - test + + build: + - Clean + - Build_Module_ModuleBuilder + - Build_NestedModules_ModuleBuilder + - Create_Changelog_Release_Output + - Generate_Conceptual_Help + - Generate_Wiki_Content + + pack: + - build + - package_module_nupkg + + hqrmtest: + - DscResource_Tests_Stop_On_Fail + + test: + - Pester_Tests_Stop_On_Fail + - Pester_If_Code_Coverage_Under_Threshold + + publish: + - Publish_Release_To_GitHub + - Publish_Module_To_gallery + - Publish_GitHub_Wiki_Content + +#################################################### +# ModuleBuilder Configuration # #################################################### CopyPaths: - DSCResources @@ -27,7 +59,7 @@ TaskHeader: | "" #################################################### -# ModuleBuilder Dependent Modules Configuration # +# Dependent Modules Configuration (Sampler) # #################################################### NestedModule: DscResource.Common: @@ -37,39 +69,7 @@ NestedModule: Exclude: PSGetModuleInfo.xml #################################################### -# Pipeline Configuration # -#################################################### -BuildWorkflow: - '.': - - build - - test - - build: - - Clean - - Build_Module_ModuleBuilder - - Build_NestedModules_ModuleBuilder - - Create_Changelog_Release_Output - - Generate_Conceptual_Help - - Generate_Wiki_Content - - pack: - - build - - package_module_nupkg - - hqrmtest: - - DscResource_Tests_Stop_On_Fail - - test: - - Pester_Tests_Stop_On_Fail - - Pester_If_Code_Coverage_Under_Threshold - - publish: - - Publish_Release_To_GitHub - - Publish_Module_To_gallery - - Publish_GitHub_Wiki_Content - -#################################################### -# PESTER Configuration # +# Pester Configuration (Sampler) # #################################################### Pester: OutputFormat: NUnitXML @@ -88,6 +88,9 @@ Pester: CodeCoverageOutputFile: JaCoCo_coverage.xml CodeCoverageOutputFileEncoding: ascii +#################################################### +# Pester Configuration (DscResource.Test) # +#################################################### DscTest: ExcludeTag: - "Common Tests - New Error-Level Script Analyzer Rules" diff --git a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 index f65a441e3..870faba9c 100644 --- a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 +++ b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 @@ -172,7 +172,7 @@ function Get-TargetResource Write-Verbose -Message ($script:localizedData.UsingPath -f $pathToSetupExecutable) - $sqlVersion = Get-SqlMajorVersion -Path $pathToSetupExecutable + $sqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable if ($SourceCredential) { @@ -984,7 +984,7 @@ function Set-TargetResource Write-Verbose -Message ($script:localizedData.UsingPath -f $pathToSetupExecutable) - $sqlVersion = Get-SqlMajorVersion -Path $pathToSetupExecutable + $sqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable # Determine features to install $featuresToInstall = '' @@ -2192,7 +2192,7 @@ function Test-TargetResource if ($getTargetResourceParameters.Action -eq 'Upgrade') { - $installerSqlVersion = Get-SqlMajorVersion -Path (Join-Path -Path $sourcePath -ChildPath 'setup.exe') + $installerSqlVersion = Get-FilePathMajorVersion -Path (Join-Path -Path $sourcePath -ChildPath 'setup.exe') $instanceSqlVersion = Get-SQLInstanceMajorVersion -InstanceName $InstanceName if ($installerSQLVersion -gt $instanceSqlVersion) @@ -2208,26 +2208,6 @@ function Test-TargetResource return $result } -<# - .SYNOPSIS - Returns the SQL Server major version from the setup.exe executable provided in the Path parameter. - - .PARAMETER Path - String containing the path to the SQL Server setup.exe executable. -#> -function Get-SqlMajorVersion -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Path - ) - - (Get-Item -Path $Path).VersionInfo.ProductVersion.Split('.')[0] -} - <# .SYNOPSIS Returns the first item value in the registry location provided in the Path parameter. diff --git a/source/DSCResources/DSC_SqlWindowsFirewall/DSC_SqlWindowsFirewall.psm1 b/source/DSCResources/DSC_SqlWindowsFirewall/DSC_SqlWindowsFirewall.psm1 index cc8d6113f..eab786a34 100644 --- a/source/DSCResources/DSC_SqlWindowsFirewall/DSC_SqlWindowsFirewall.psm1 +++ b/source/DSCResources/DSC_SqlWindowsFirewall/DSC_SqlWindowsFirewall.psm1 @@ -78,7 +78,7 @@ function Get-TargetResource $script:localizedData.UsingPath -f $pathToSetupExecutable ) - $sqlVersion = Get-SqlMajorVersion -Path $pathToSetupExecutable + $sqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable Write-Verbose -Message ( $script:localizedData.MajorVersion -f $sqlVersion @@ -401,7 +401,7 @@ function Set-TargetResource $script:localizedData.UsingPath -f $pathToSetupExecutable ) - $sqlVersion = Get-SqlMajorVersion -Path $pathToSetupExecutable + $sqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable Write-Verbose -Message ( $script:localizedData.MajorVersion -f $sqlVersion @@ -864,25 +864,4 @@ function Test-IsFirewallRuleInDesiredState return $isRuleInDesiredState } -<# - .SYNOPSIS - Returns the SQL Server major version from the setup.exe executable provided - in the Path parameter. - - .PARAMETER Path - String containing the path to the SQL Server setup.exe executable. -#> -function Get-SqlMajorVersion -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $path - ) - - (Get-Item -Path $path).VersionInfo.ProductVersion.Split('.')[0] -} - Export-ModuleMember -Function *-TargetResource diff --git a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 index ba2bae2a2..9faced817 100644 --- a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 +++ b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 @@ -54,6 +54,7 @@ 'Import-Assembly' 'Set-PSModulePath' 'ConvertTo-ServerInstanceName' + 'Get-FilePathMajorVersion' ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. diff --git a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index 482e7219b..ec9a53ea9 100644 --- a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -2374,3 +2374,24 @@ function ConvertTo-ServerInstanceName return $serverInstance } + +<# + .SYNOPSIS + Returns the SQL Server major version from the setup.exe executable provided + in the Path parameter. + + .PARAMETER Path + String containing the path to the SQL Server setup.exe executable. +#> +function Get-FilePathMajorVersion +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Path + ) + + (Get-Item -Path $Path).VersionInfo.ProductVersion.Split('.')[0] +} diff --git a/tests/Unit/DSC_SqlSetup.Tests.ps1 b/tests/Unit/DSC_SqlSetup.Tests.ps1 index eab88e903..a4f5b90b5 100644 --- a/tests/Unit/DSC_SqlSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlSetup.Tests.ps1 @@ -193,7 +193,7 @@ try # General mocks Mock -CommandName Get-PSDrive - Mock -CommandName Get-SqlMajorVersion -MockWith $mockGetSqlMajorVersion + Mock -CommandName Get-FilePathMajorVersion -MockWith $mockGetSqlMajorVersion Mock -CommandName Get-RegistryPropertyValue -ParameterFilter { $Name -eq 'ImagePath' @@ -1610,7 +1610,7 @@ try } } - Mock -CommandName Get-SqlMajorVersion -MockWith { + Mock -CommandName Get-FilePathMajorVersion -MockWith { return '15' } @@ -2071,7 +2071,7 @@ try # General mocks Mock -CommandName Get-PSDrive Mock -CommandName Import-SQLPSModule - Mock -CommandName Get-SqlMajorVersion -MockWith $mockGetSqlMajorVersion + Mock -CommandName Get-FilePathMajorVersion -MockWith $mockGetSqlMajorVersion # Mocking SharedDirectory and SharedWowDirectory (when not previously installed) Mock -CommandName Get-ItemProperty diff --git a/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 b/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 index bbc9f411e..45b533367 100644 --- a/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 +++ b/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 @@ -411,18 +411,9 @@ try } $mockSetNetFirewallRule = $mockNewNetFirewallRule - $mockGetItem_SqlMajorVersion = { - return New-Object -TypeName Object | - Add-Member -MemberType ScriptProperty -Name VersionInfo -Value { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name 'ProductVersion' -Value ('{0}.0.0000.00000' -f $mockCurrentSqlMajorVersion) -PassThru -Force - } -PassThru -Force + $mockGetSqlMajorVersion = { + return $mockCurrentSqlMajorVersion } - - $mockGetItem_SqlMajorVersion_ParameterFilter = { - $Path -eq $mockCurrentPathToSetupExecutable - } - #endregion Function mocks # Default parameters that are used for the It-blocks @@ -438,7 +429,7 @@ try BeforeEach { # General mocks - Mock -CommandName Get-Item -ParameterFilter $mockGetItem_SqlMajorVersion_ParameterFilter -MockWith $mockGetItem_SqlMajorVersion -Verifiable + Mock -CommandName Get-FilePathMajorVersion -MockWith $mockGetSqlMajorVersion -Verifiable # Mock SQL Server Database Engine registry for Instance ID. Mock -CommandName Get-ItemProperty ` @@ -1028,7 +1019,7 @@ try BeforeEach { # General mocks - Mock -CommandName Get-Item -ParameterFilter $mockGetItem_SqlMajorVersion_ParameterFilter -MockWith $mockGetItem_SqlMajorVersion -Verifiable + Mock -CommandName Get-FilePathMajorVersion -MockWith $mockGetSqlMajorVersion -Verifiable # Mock SQL Server Database Engine registry for Instance ID. Mock -CommandName Get-ItemProperty ` @@ -1323,7 +1314,7 @@ try BeforeEach { # General mocks - Mock -CommandName Get-Item -ParameterFilter $mockGetItem_SqlMajorVersion_ParameterFilter -MockWith $mockGetItem_SqlMajorVersion -Verifiable + Mock -CommandName Get-FilePathMajorVersion -MockWith $mockGetSqlMajorVersion -Verifiable # Mock SQL Server Database Engine registry for Instance ID. Mock -CommandName Get-ItemProperty ` diff --git a/tests/Unit/SqlServerDsc.Common.Tests.ps1 b/tests/Unit/SqlServerDsc.Common.Tests.ps1 index de8765263..1bae2b3e3 100644 --- a/tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -3446,4 +3446,24 @@ InModuleScope $script:subModuleName { $result | Should -BeExactly ('{0}\{1}' -f $env:COMPUTERNAME, 'MyInstance') } } + + Describe 'SqlServerDsc.Common\Get-FilePathMajorVersion' { + BeforeAll { + $mockGetItem_SqlMajorVersion = { + return New-Object -TypeName Object | + Add-Member -MemberType ScriptProperty -Name VersionInfo -Value { + return New-Object -TypeName Object | + Add-Member -MemberType NoteProperty -Name 'ProductVersion' -Value '10.0.0000.00000' -PassThru -Force + } -PassThru -Force + } + + Mock -CommandName Get-Item -MockWith $mockGetItem_SqlMajorVersion + } + + It 'Should return correct version' { + $result = Get-FilePathMajorVersion -Path 'C:\AnyPath\Setup.exe' + + $result | Should -Be '10' + } + } }