diff --git a/CHANGELOG.md b/CHANGELOG.md index eb6aadfcd..cb3e57f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ DscResource.Template. - Moved all helper functions from SqlServerDscHelper.psm1 to DscResource.Common. - Renamed Test-SqlDscParameterState to Test-DscParameterState. + - New-TerminatingError error text for a missing localized message now matches + the output even if the "missing localized message" localized message is + also missing. - Added helper module DscResource.LocalizationHelper from the repository DscResource.Template, this replaces the helper module CommonResourceHelper.psm1. - Cleaned up unit tests, mostly around loading cmdlet stubs and loading @@ -59,10 +62,6 @@ - Fix MatchDatabaseOwner to check for CONTROL SERVER, IMPERSONATE LOGIN, or CONTROL LOGIN permission in addition to IMPERSONATE ANY LOGIN. - Update and fix MatchDatabaseOwner help text. -- Changes to xSQLServerHelper - - New-TerminatingError error text for a missing localized message now matches - the output even if the "missing localized message" localized message is - also missing. - Changes to SqlAG - Updated documentation on the behaviour of defaults as they only apply when creating a group. @@ -72,6 +71,10 @@ parameters will still change existing replicas ([issue #1244](https://github.com/PowerShell/SqlServerDsc/issues/1244)). - ReadOnlyRoutingList now gets updated without throwing an error on the first run ([issue #518](https://github.com/PowerShell/SqlServerDsc/issues/518)). +- Changes to SqlDatabaseDefaultLocation + - No longer does the Test-TargetResource fail on the second test run + when the backup file path was changed, and the path was ending with + a backslash ([issue #1307](https://github.com/PowerShell/SqlServerDsc/issues/1307)). ## 12.3.0.0 diff --git a/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 index a50820d06..d6f908048 100644 --- a/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 +++ b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 @@ -147,6 +147,12 @@ Function Set-TargetResource $ProcessOnlyOnActiveNode ) + if ($Type -eq 'Backup') + { + # Ending backslash is removed because of issue #1307. + $Path = $Path.TrimEnd('\') + } + # Make sure the Path exists, needs to be cluster aware as well for this check if (-Not (Test-Path $Path)) { @@ -265,6 +271,12 @@ function Test-TargetResource Write-Verbose -Message ($script:localizedData.TestingCurrentPath -f $Type) + if ($Type -eq 'Backup') + { + # Ending backslash is removed because of issue #1307. + $Path = $Path.TrimEnd('\') + } + $getTargetResourceParameters = @{ InstanceName = $InstanceName ServerName = $ServerName diff --git a/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 index 8a2ccde20..26a8d617f 100644 --- a/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 @@ -79,7 +79,7 @@ try } $resourceCurrentState.Type | Should -Be 'Data' - ( Join-Path -Path $resourceCurrentState.Path -ChildPath '' ) | Should -Be ( Join-Path -Path $ConfigurationData.AllNodes.DataFilePath -ChildPath '' ) + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.DataFilePath } It 'Should return $true when Test-DscConfiguration is run' { @@ -126,7 +126,7 @@ try } $resourceCurrentState.Type | Should -Be 'Log' - ( Join-Path -Path $resourceCurrentState.Path -ChildPath '' ) | Should -Be ( Join-Path -Path $ConfigurationData.AllNodes.LogFilePath -ChildPath '' ) + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.LogFilePath } It 'Should return $true when Test-DscConfiguration is run' { @@ -173,7 +173,8 @@ try } $resourceCurrentState.Type | Should -Be 'Backup' - ( Join-Path -Path $resourceCurrentState.Path -ChildPath '' ) | Should -Be ( Join-Path -Path $ConfigurationData.AllNodes.BackupFilePath -ChildPath '' ) + # Ending backslash is removed because of regression test for issue #1307. + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.BackupFilePath.TrimEnd('\') } It 'Should return $true when Test-DscConfiguration is run' { diff --git a/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 index 92c84c78e..acb624eec 100644 --- a/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 +++ b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 @@ -27,6 +27,8 @@ else DataFilePath = 'C:\SQLData\' LogFilePath = 'C:\SQLLog\' + + # Ending backslash is regression test for issue #1307. BackupFilePath = 'C:\Backups\' CertificateFile = $env:DscPublicCertificatePath diff --git a/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 index 1326363ea..ae3eb3636 100644 --- a/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 @@ -62,7 +62,10 @@ try $mockInstanceName = 'MSSQLSERVER' $mockSQLDataPath = 'C:\Program Files\Data\' $mockSqlLogPath = 'C:\Program Files\Log\' + + # Ending backslash is regression test for issue #1307. $mockSqlBackupPath = 'C:\Program Files\Backup\' + $mockSqlAlterDataPath = 'C:\Program Files\' $mockSqlAlterLogPath = 'C:\Program Files\' $mockSqlAlterBackupPath = 'C:\Program Files\' @@ -92,7 +95,8 @@ try Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru -Force | Add-Member -MemberType NoteProperty -Name DefaultFile -Value $mockSqlDataPath -PassThru -Force | Add-Member -MemberType NoteProperty -Name DefaultLog -Value $mockSqlLogPath -PassThru -Force | - Add-Member -MemberType NoteProperty -Name BackupDirectory -Value $mockSqlBackupPath -PassThru -Force | + # Ending backslash is removed because of regression test for issue #1307. + Add-Member -MemberType NoteProperty -Name BackupDirectory -Value $mockSqlBackupPath.TrimEnd('\') -PassThru -Force | Add-Member -MemberType ScriptMethod -Name Alter -Value { if ($mockInvalidOperationForAlterMethod) { @@ -101,33 +105,27 @@ try $script:WasMethodAlterCalled = $true } -PassThru -Force } - - $testCases = @( - @{ - Type = 'Data' - Path = $mockSqlDataPath - AlterPath = $mockSqlAlterDataPath - ExpectedAlterPath = $mockExpectedAlterDataPath - InvalidPath = $mockInvalidPathForData - }, - @{ - Type = 'Log' - Path = $mockSqlLogPath - AlterPath = $mockSqlAlterLogPath - ExpectedAlterPath = $mockExpectedAlterLogPath - InvalidPath = $mockInvalidPathForLog - }, - @{ - Type = 'Backup' - Path = $mockSqlBackupPath - AlterPath = $mockSqlAlterBackupPath - ExpectedAlterPath = $mockExpectedAlterBackupPath - InvalidPath = $mockInvalidPathForBackup - } - ) #endregion Describe 'MSFT_SqlDatabaseDefaultLocation\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $testCases = @( + @{ + Type = 'Data' + Path = $mockSqlDataPath + }, + @{ + Type = 'Log' + Path = $mockSqlLogPath + }, + @{ + Type = 'Backup' + # Ending backslash is removed because of regression test for issue #1307. + Path = $mockSqlBackupPath.TrimEnd('\') + } + ) + } + BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Test-ActiveNode -Mockwith { @@ -162,6 +160,25 @@ try } Describe 'MSFT_SqlDatabaseDefaultLocation\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $testCases = @( + @{ + Type = 'Data' + Path = $mockSqlDataPath + AlterPath = $mockSqlAlterDataPath + }, + @{ + Type = 'Log' + Path = $mockSqlLogPath + AlterPath = $mockSqlAlterLogPath + }, + @{ + Type = 'Backup' + Path = $mockSqlBackupPath + AlterPath = $mockSqlAlterBackupPath + } + ) + } BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Test-ActiveNode -MockWith { @@ -240,6 +257,32 @@ try } Describe 'MSFT_SqlDatabaseDefaultLocation\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $testCases = @( + @{ + Type = 'Data' + Path = $mockSqlDataPath + AlterPath = $mockSqlAlterDataPath + ExpectedAlterPath = $mockExpectedAlterDataPath + InvalidPath = $mockInvalidPathForData + }, + @{ + Type = 'Log' + Path = $mockSqlLogPath + AlterPath = $mockSqlAlterLogPath + ExpectedAlterPath = $mockExpectedAlterLogPath + InvalidPath = $mockInvalidPathForLog + }, + @{ + Type = 'Backup' + Path = $mockSqlBackupPath + AlterPath = $mockSqlAlterBackupPath + ExpectedAlterPath = $mockExpectedAlterBackupPath + InvalidPath = $mockInvalidPathForBackup + } + ) + } + BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Restart-SqlService -Verifiable