Skip to content

Commit

Permalink
Changes to SqlDatabaseDefaultLocation
Browse files Browse the repository at this point in the history
- 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 dsccommunity#1307).
  • Loading branch information
johlju committed Mar 17, 2019
1 parent 94614f8 commit 3e992f9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 32 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down Expand Up @@ -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' {
Expand Down Expand Up @@ -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' {
Expand Down
2 changes: 2 additions & 0 deletions Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 68 additions & 25 deletions Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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\'
Expand Down Expand Up @@ -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)
{
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e992f9

Please sign in to comment.