Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `New-SqlDscAudit`
- Fixed parameter validation to prevent the `ReserveDiskSpace` parameter from
being used with the `FileWithMaxFiles` parameter set (when only `MaximumFiles`
is specified without `MaximumFileSize`). This combination always resulted in
a SQL Server error because `RESERVE_DISK_SPACE` cannot be specified when
`MAXSIZE = UNLIMITED`. The `ReserveDiskSpace` parameter now correctly requires
both `MaximumFiles` and `MaximumFileSize` to be specified
([issue #2289](https://github.com/dsccommunity/SqlServerDsc/issues/2289)).
- `Add-SqlDscTraceFlag` and `Remove-SqlDscTraceFlag`
- Fixed parameter binding error when `ErrorAction` was specified both
explicitly and via `PSBoundParameters` by using `Remove-CommonParameter`
Expand Down
3 changes: 1 addition & 2 deletions source/Public/New-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

.PARAMETER ReserveDiskSpace
Specifies if the needed file space should be reserved. To use this parameter
the parameter **MaximumFiles** must also be used.
the parameters **MaximumFiles** and **MaximumFileSize** must also be used.

.PARAMETER MaximumFiles
Specifies the number of files on disk.
Expand Down Expand Up @@ -188,7 +188,6 @@ function New-SqlDscAudit
[System.UInt32]
$MaximumFiles,

[Parameter(ParameterSetName = 'FileWithMaxFiles')]
[Parameter(ParameterSetName = 'FileWithSizeAndMaxFiles')]
[System.Management.Automation.SwitchParameter]
$ReserveDiskSpace,
Expand Down
70 changes: 1 addition & 69 deletions tests/Unit/Public/New-SqlDscAudit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Describe 'New-SqlDscAudit' -Tag 'Public' {
}
@{
MockParameterSetName = 'FileWithMaxFiles'
MockExpectedParameters = '-ServerObject <Server> -Name <string> -Path <string> -MaximumFiles <uint> [-AuditFilter <string>] [-OnFailure <string>] [-QueueDelay <uint>] [-AuditGuid <string>] [-Force] [-Refresh] [-PassThru] [-ReserveDiskSpace] [-WhatIf] [-Confirm] [<CommonParameters>]'
MockExpectedParameters = '-ServerObject <Server> -Name <string> -Path <string> -MaximumFiles <uint> [-AuditFilter <string>] [-OnFailure <string>] [-QueueDelay <uint>] [-AuditGuid <string>] [-Force] [-Refresh] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
}
@{
MockParameterSetName = 'FileWithMaxRolloverFiles'
Expand Down Expand Up @@ -493,74 +493,6 @@ Describe 'New-SqlDscAudit' -Tag 'Public' {
}
}

Context 'When passing file audit optional parameters MaximumFiles and ReserveDiskSpace' {
BeforeAll {
$script:mockCreateAuditObject = $null

Mock -CommandName New-Object -ParameterFilter {
$TypeName -eq 'Microsoft.SqlServer.Management.Smo.Audit'
} -MockWith {
<#
The Audit object is created in the script scope so that the
properties can be validated.
#>
$script:mockCreateAuditObject = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Audit' -ArgumentList @(
$PesterBoundParameters.ArgumentList[0],
$PesterBoundParameters.ArgumentList[1]
) |
Add-Member -MemberType 'ScriptMethod' -Name 'Create' -Value {
$script:mockMethodCreateCallCount += 1
} -PassThru -Force

return $script:mockCreateAuditObject
}

Mock -CommandName Get-SqlDscAudit

$mockServerObject = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
$mockServerObject.InstanceName = 'TestInstance'

$mockDefaultParameters = @{
ServerObject = $mockServerObject
Name = 'Log1'
Path = Get-TemporaryFolder
Force = $true
}
}

BeforeEach {
$script:mockMethodCreateCallCount = 0
}

It 'Should call the mocked method and have correct values in the object' {
New-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace @mockDefaultParameters

# This is the object created by the mock and modified by the command.
$mockCreateAuditObject.Name | Should -Be 'Log1'
$mockCreateAuditObject.DestinationType | Should -Be 'File'
$mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder)
$mockCreateAuditObject.MaximumFiles | Should -Be 2
$mockCreateAuditObject.ReserveDiskSpace | Should -BeTrue

$mockMethodCreateCallCount | Should -Be 1
}

Context 'When ReserveDiskSpace is set to $false' {
It 'Should call the mocked method and have correct values in the object' {
New-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace:$false @mockDefaultParameters

# This is the object created by the mock and modified by the command.
$mockCreateAuditObject.Name | Should -Be 'Log1'
$mockCreateAuditObject.DestinationType | Should -Be 'File'
$mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder)
$mockCreateAuditObject.MaximumFiles | Should -Be 2
$mockCreateAuditObject.ReserveDiskSpace | Should -BeFalse

$mockMethodCreateCallCount | Should -Be 1
}
}
}

Context 'When passing file audit optional parameters MaximumRolloverFiles' {
BeforeAll {
$script:mockCreateAuditObject = $null
Expand Down
Loading