Skip to content

Commit 8acbed1

Browse files
authored
New-SqlDscAudit: Fix ReserveDiskSpace parameter requirements (#2292)
1 parent 6e3fbfb commit 8acbed1

File tree

3 files changed

+10
-71
lines changed

3 files changed

+10
-71
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
109109

110110
### Fixed
111111

112+
- `New-SqlDscAudit`
113+
- Fixed parameter validation to prevent the `ReserveDiskSpace` parameter from
114+
being used with the `FileWithMaxFiles` parameter set (when only `MaximumFiles`
115+
is specified without `MaximumFileSize`). This combination always resulted in
116+
a SQL Server error because `RESERVE_DISK_SPACE` cannot be specified when
117+
`MAXSIZE = UNLIMITED`. The `ReserveDiskSpace` parameter now correctly requires
118+
both `MaximumFiles` and `MaximumFileSize` to be specified
119+
([issue #2289](https://github.com/dsccommunity/SqlServerDsc/issues/2289)).
112120
- `Add-SqlDscTraceFlag` and `Remove-SqlDscTraceFlag`
113121
- Fixed parameter binding error when `ErrorAction` was specified both
114122
explicitly and via `PSBoundParameters` by using `Remove-CommonParameter`

source/Public/New-SqlDscAudit.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
4848
.PARAMETER ReserveDiskSpace
4949
Specifies if the needed file space should be reserved. To use this parameter
50-
the parameter **MaximumFiles** must also be used.
50+
the parameters **MaximumFiles** and **MaximumFileSize** must also be used.
5151
5252
.PARAMETER MaximumFiles
5353
Specifies the number of files on disk.
@@ -188,7 +188,6 @@ function New-SqlDscAudit
188188
[System.UInt32]
189189
$MaximumFiles,
190190

191-
[Parameter(ParameterSetName = 'FileWithMaxFiles')]
192191
[Parameter(ParameterSetName = 'FileWithSizeAndMaxFiles')]
193192
[System.Management.Automation.SwitchParameter]
194193
$ReserveDiskSpace,

tests/Unit/Public/New-SqlDscAudit.Tests.ps1

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Describe 'New-SqlDscAudit' -Tag 'Public' {
6565
}
6666
@{
6767
MockParameterSetName = 'FileWithMaxFiles'
68-
MockExpectedParameters = '-ServerObject <Server> -Name <string> -Path <string> -MaximumFiles <uint> [-AuditFilter <string>] [-OnFailure <string>] [-QueueDelay <uint>] [-AuditGuid <string>] [-Force] [-Refresh] [-PassThru] [-ReserveDiskSpace] [-WhatIf] [-Confirm] [<CommonParameters>]'
68+
MockExpectedParameters = '-ServerObject <Server> -Name <string> -Path <string> -MaximumFiles <uint> [-AuditFilter <string>] [-OnFailure <string>] [-QueueDelay <uint>] [-AuditGuid <string>] [-Force] [-Refresh] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
6969
}
7070
@{
7171
MockParameterSetName = 'FileWithMaxRolloverFiles'
@@ -493,74 +493,6 @@ Describe 'New-SqlDscAudit' -Tag 'Public' {
493493
}
494494
}
495495

496-
Context 'When passing file audit optional parameters MaximumFiles and ReserveDiskSpace' {
497-
BeforeAll {
498-
$script:mockCreateAuditObject = $null
499-
500-
Mock -CommandName New-Object -ParameterFilter {
501-
$TypeName -eq 'Microsoft.SqlServer.Management.Smo.Audit'
502-
} -MockWith {
503-
<#
504-
The Audit object is created in the script scope so that the
505-
properties can be validated.
506-
#>
507-
$script:mockCreateAuditObject = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Audit' -ArgumentList @(
508-
$PesterBoundParameters.ArgumentList[0],
509-
$PesterBoundParameters.ArgumentList[1]
510-
) |
511-
Add-Member -MemberType 'ScriptMethod' -Name 'Create' -Value {
512-
$script:mockMethodCreateCallCount += 1
513-
} -PassThru -Force
514-
515-
return $script:mockCreateAuditObject
516-
}
517-
518-
Mock -CommandName Get-SqlDscAudit
519-
520-
$mockServerObject = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
521-
$mockServerObject.InstanceName = 'TestInstance'
522-
523-
$mockDefaultParameters = @{
524-
ServerObject = $mockServerObject
525-
Name = 'Log1'
526-
Path = Get-TemporaryFolder
527-
Force = $true
528-
}
529-
}
530-
531-
BeforeEach {
532-
$script:mockMethodCreateCallCount = 0
533-
}
534-
535-
It 'Should call the mocked method and have correct values in the object' {
536-
New-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace @mockDefaultParameters
537-
538-
# This is the object created by the mock and modified by the command.
539-
$mockCreateAuditObject.Name | Should -Be 'Log1'
540-
$mockCreateAuditObject.DestinationType | Should -Be 'File'
541-
$mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder)
542-
$mockCreateAuditObject.MaximumFiles | Should -Be 2
543-
$mockCreateAuditObject.ReserveDiskSpace | Should -BeTrue
544-
545-
$mockMethodCreateCallCount | Should -Be 1
546-
}
547-
548-
Context 'When ReserveDiskSpace is set to $false' {
549-
It 'Should call the mocked method and have correct values in the object' {
550-
New-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace:$false @mockDefaultParameters
551-
552-
# This is the object created by the mock and modified by the command.
553-
$mockCreateAuditObject.Name | Should -Be 'Log1'
554-
$mockCreateAuditObject.DestinationType | Should -Be 'File'
555-
$mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder)
556-
$mockCreateAuditObject.MaximumFiles | Should -Be 2
557-
$mockCreateAuditObject.ReserveDiskSpace | Should -BeFalse
558-
559-
$mockMethodCreateCallCount | Should -Be 1
560-
}
561-
}
562-
}
563-
564496
Context 'When passing file audit optional parameters MaximumRolloverFiles' {
565497
BeforeAll {
566498
$script:mockCreateAuditObject = $null

0 commit comments

Comments
 (0)