From 0119c7d122400427641aa977c6917784018e529a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:22:45 +0000 Subject: [PATCH 1/6] Initial plan From 57b7a715e82f721d12e13745e2bbf7de21a4a489 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:34:30 +0000 Subject: [PATCH 2/6] Add comprehensive integration test for New-SqlDscAudit command Co-authored-by: johlju <7189721+johlju@users.noreply.github.com> --- CHANGELOG.md | 3 + azure-pipelines.yml | 1 + .../New-SqlDscAudit.Integration.Tests.ps1 | 344 ++++++++++++++++++ tests/Integration/Commands/README.md | 1 + 4 files changed, 349 insertions(+) create mode 100644 tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index b224ca2cbc..4bb7a5d64c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added integration tests for `Remove-SqlDscAudit` command to ensure it functions correctly in real environments [issue #2241](https://github.com/dsccommunity/SqlServerDsc/issues/2241). +- Added integration tests for `New-SqlDscAudit` command to ensure it functions + correctly in real environments + [issue #2226](https://github.com/dsccommunity/SqlServerDsc/issues/2226). ### Fixed diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 103503d7d8..c7b24053a6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -315,6 +315,7 @@ stages: 'tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1' 'tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1' 'tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1' + 'tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1' 'tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1' 'tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1' 'tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1' diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 new file mode 100644 index 0000000000..04d1520eb7 --- /dev/null +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -0,0 +1,344 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies have not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + } +} + +BeforeAll { + $script:moduleName = 'SqlServerDsc' + + Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' +} + +Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { + BeforeAll { + # Starting the named instance SQL Server service prior to running tests. + Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + + $script:mockInstanceName = 'DSCSQLTEST' + $script:mockComputerName = Get-ComputerName + + $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. + $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + + $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) + + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + + # Create a temporary directory for file audits if it doesn't exist + $script:testAuditPath = Join-Path -Path $env:TEMP -ChildPath 'SqlDscTestAudits' + if (-not (Test-Path -Path $script:testAuditPath)) + { + $null = New-Item -Path $script:testAuditPath -ItemType Directory -Force + } + } + + AfterAll { + # Clean up any test audits that might remain + $testAudits = Get-SqlDscAudit -ServerObject $script:serverObject -ErrorAction 'SilentlyContinue' | + Where-Object { $_.Name -like 'SqlDscTestAudit*' } + + foreach ($audit in $testAudits) + { + try + { + Remove-SqlDscAudit -AuditObject $audit -Force -ErrorAction 'SilentlyContinue' + } + catch + { + # Ignore cleanup errors + } + } + + Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject + + # Clean up temporary directory + if (Test-Path -Path $script:testAuditPath) + { + Remove-Item -Path $script:testAuditPath -Recurse -Force -ErrorAction 'SilentlyContinue' + } + + # Stop the named instance SQL Server service to save memory on the build worker. + Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + } + + Context 'When creating a new application log audit' { + BeforeEach { + $script:testAuditName = 'SqlDscTestAudit_AppLog_' + (Get-Random) + } + + AfterEach { + # Clean up the audit created in this test + $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' + if ($auditToRemove) + { + Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' + } + } + + It 'Should create an application log audit successfully' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:testAuditName + $result.DestinationType | Should -Be 'ApplicationLog' + $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' + + # Verify the audit exists in the server + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit | Should -Not -BeNullOrEmpty + $createdAudit.Name | Should -Be $script:testAuditName + $createdAudit.DestinationType | Should -Be 'ApplicationLog' + } + + It 'Should create a security log audit successfully' { + $securityLogAuditName = 'SqlDscTestAudit_SecLog_' + (Get-Random) + + try + { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -LogType 'SecurityLog' -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $securityLogAuditName + $result.DestinationType | Should -Be 'SecurityLog' + + # Verify the audit exists in the server + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -ErrorAction Stop + $createdAudit | Should -Not -BeNullOrEmpty + $createdAudit.DestinationType | Should -Be 'SecurityLog' + } + finally + { + # Clean up + $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -ErrorAction 'SilentlyContinue' + if ($auditToRemove) + { + Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' + } + } + } + + It 'Should support PassThru parameter' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' + $result.Name | Should -Be $script:testAuditName + } + } + + Context 'When creating a new file audit' { + BeforeEach { + $script:testAuditName = 'SqlDscTestAudit_File_' + (Get-Random) + } + + AfterEach { + # Clean up the audit created in this test + $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' + if ($auditToRemove) + { + Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' + } + } + + It 'Should create a file audit successfully' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:testAuditName + $result.DestinationType | Should -Be 'File' + $result.FilePath | Should -Be $script:testAuditPath + + # Verify the audit exists in the server + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit | Should -Not -BeNullOrEmpty + $createdAudit.DestinationType | Should -Be 'File' + $createdAudit.FilePath | Should -Be $script:testAuditPath + } + + It 'Should create a file audit with maximum file size' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.MaximumFileSize | Should -Be 100 + $result.MaximumFileSizeUnit | Should -Be 'MB' + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.MaximumFileSize | Should -Be 100 + $createdAudit.MaximumFileSizeUnit | Should -Be 'MB' + } + + It 'Should create a file audit with maximum files and reserve disk space' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -ReserveDiskSpace -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.MaximumFiles | Should -Be 5 + $result.ReserveDiskSpace | Should -BeTrue + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.MaximumFiles | Should -Be 5 + $createdAudit.ReserveDiskSpace | Should -BeTrue + } + + It 'Should create a file audit with maximum rollover files' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 10 -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.MaximumRolloverFiles | Should -Be 10 + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.MaximumRolloverFiles | Should -Be 10 + } + } + + Context 'When creating an audit with advanced options' { + BeforeEach { + $script:testAuditName = 'SqlDscTestAudit_Advanced_' + (Get-Random) + } + + AfterEach { + # Clean up the audit created in this test + $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' + if ($auditToRemove) + { + Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' + } + } + + It 'Should create an audit with OnFailure setting' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'Continue' -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.OnFailure | Should -Be 'Continue' + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.OnFailure | Should -Be 'Continue' + } + + It 'Should create an audit with QueueDelay setting' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 5000 -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.QueueDelay | Should -Be 5000 + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.QueueDelay | Should -Be 5000 + } + + It 'Should create an audit with AuditGuid setting' { + $testGuid = [System.Guid]::NewGuid().ToString() + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $testGuid -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Guid | Should -Be $testGuid + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.Guid | Should -Be $testGuid + } + + It 'Should create an audit with AuditFilter setting' { + $testFilter = "([database_name] = 'master')" + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $testFilter -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Filter | Should -Be $testFilter + + # Verify the audit exists with correct properties + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit.Filter | Should -Be $testFilter + } + + It 'Should support Refresh parameter' { + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Refresh -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:testAuditName + + # Verify the audit exists + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit | Should -Not -BeNullOrEmpty + } + } + + Context 'When creating an audit using pipeline input' { + BeforeEach { + $script:testAuditName = 'SqlDscTestAudit_Pipeline_' + (Get-Random) + } + + AfterEach { + # Clean up the audit created in this test + $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' + if ($auditToRemove) + { + Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' + } + } + + It 'Should support pipeline input with server object' { + $result = $script:serverObject | New-SqlDscAudit -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:testAuditName + + # Verify the audit exists + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit | Should -Not -BeNullOrEmpty + } + } + + Context 'When handling error conditions' { + BeforeEach { + $script:testAuditName = 'SqlDscTestAudit_Error_' + (Get-Random) + } + + AfterEach { + # Clean up the audit created in this test + $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' + if ($auditToRemove) + { + Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' + } + } + + It 'Should throw error when trying to create an audit that already exists' { + # First, create an audit + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + + # Then try to create another audit with the same name + { New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop } | + Should -Throw + } + + It 'Should throw error when path does not exist for file audit' { + $nonExistentPath = Join-Path -Path $env:TEMP -ChildPath 'NonExistentPath' + + { New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $nonExistentPath -Force -ErrorAction Stop } | + Should -Throw + } + } +} \ No newline at end of file diff --git a/tests/Integration/Commands/README.md b/tests/Integration/Commands/README.md index 768f7bfa99..f5c6afd333 100644 --- a/tests/Integration/Commands/README.md +++ b/tests/Integration/Commands/README.md @@ -67,6 +67,7 @@ Set-SqlDscDatabase | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTES Test-SqlDscDatabase | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Get-SqlDscAgentAlert | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - New-SqlDscAgentAlert | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test alerts +New-SqlDscAudit | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test audits Set-SqlDscAgentAlert | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Test-SqlDscAgentAlertProperty | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Test-SqlDscIsAgentAlert | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - From 6d27b8967dc02da24764d83ec184289f50046783 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 16:16:05 +0000 Subject: [PATCH 3/6] Address feedback: Add PassThru parameter, fix error message, and ensure proper file ending Co-authored-by: johlju <7189721+johlju@users.noreply.github.com> --- .../New-SqlDscAudit.Integration.Tests.ps1 | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 04d1520eb7..94270d938d 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -19,7 +19,7 @@ BeforeDiscovery { } catch [System.IO.FileNotFoundException] { - throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' } } @@ -96,7 +96,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create an application log audit successfully' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName @@ -115,7 +115,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', try { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -LogType 'SecurityLog' -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $securityLogAuditName @@ -161,7 +161,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit successfully' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName @@ -176,7 +176,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit with maximum file size' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.MaximumFileSize | Should -Be 100 @@ -189,7 +189,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit with maximum files and reserve disk space' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -ReserveDiskSpace -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -ReserveDiskSpace -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.MaximumFiles | Should -Be 5 @@ -202,7 +202,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit with maximum rollover files' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 10 -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 10 -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.MaximumRolloverFiles | Should -Be 10 @@ -228,7 +228,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create an audit with OnFailure setting' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'Continue' -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'Continue' -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.OnFailure | Should -Be 'Continue' @@ -239,7 +239,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create an audit with QueueDelay setting' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 5000 -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 5000 -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.QueueDelay | Should -Be 5000 @@ -251,7 +251,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create an audit with AuditGuid setting' { $testGuid = [System.Guid]::NewGuid().ToString() - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $testGuid -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $testGuid -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Guid | Should -Be $testGuid @@ -263,7 +263,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create an audit with AuditFilter setting' { $testFilter = "([database_name] = 'master')" - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $testFilter -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $testFilter -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Filter | Should -Be $testFilter @@ -274,7 +274,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should support Refresh parameter' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Refresh -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Refresh -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName @@ -300,7 +300,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should support pipeline input with server object' { - $result = $script:serverObject | New-SqlDscAudit -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $result = $script:serverObject | New-SqlDscAudit -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName @@ -341,4 +341,4 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', Should -Throw } } -} \ No newline at end of file +} From 7e7dd29e4e9acd8512967f80fca15c23768cecc8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 18:12:59 +0000 Subject: [PATCH 4/6] Fix integration test issues: Use SQL Server accessible path and add required parameters for ReserveDiskSpace Co-authored-by: johlju <7189721+johlju@users.noreply.github.com> --- .../Commands/New-SqlDscAudit.Integration.Tests.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 94270d938d..17aaa7735a 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -45,7 +45,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop # Create a temporary directory for file audits if it doesn't exist - $script:testAuditPath = Join-Path -Path $env:TEMP -ChildPath 'SqlDscTestAudits' + $script:testAuditPath = 'C:\Temp\SqlDscTestAudits' if (-not (Test-Path -Path $script:testAuditPath)) { $null = New-Item -Path $script:testAuditPath -ItemType Directory -Force @@ -189,15 +189,19 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit with maximum files and reserve disk space' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -ReserveDiskSpace -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -MaximumFileSize 50 -MaximumFileSizeUnit 'Megabyte' -ReserveDiskSpace -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty $result.MaximumFiles | Should -Be 5 + $result.MaximumFileSize | Should -Be 50 + $result.MaximumFileSizeUnit | Should -Be 'MB' $result.ReserveDiskSpace | Should -BeTrue # Verify the audit exists with correct properties $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop $createdAudit.MaximumFiles | Should -Be 5 + $createdAudit.MaximumFileSize | Should -Be 50 + $createdAudit.MaximumFileSizeUnit | Should -Be 'MB' $createdAudit.ReserveDiskSpace | Should -BeTrue } From fdc6662920524a0e196942c7ba0b4894d112b658 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 18:17:53 +0000 Subject: [PATCH 5/6] Fix AuditFilter test to expect SQL Server normalized filter expression Co-authored-by: johlju <7189721+johlju@users.noreply.github.com> --- .../Commands/New-SqlDscAudit.Integration.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 17aaa7735a..1ee2776752 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -267,14 +267,15 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create an audit with AuditFilter setting' { $testFilter = "([database_name] = 'master')" + $expectedFilter = "([database_name]='master')" # SQL Server normalizes the filter by removing spaces $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $testFilter -PassThru -Force -ErrorAction Stop $result | Should -Not -BeNullOrEmpty - $result.Filter | Should -Be $testFilter + $result.Filter | Should -Be $expectedFilter # Verify the audit exists with correct properties $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop - $createdAudit.Filter | Should -Be $testFilter + $createdAudit.Filter | Should -Be $expectedFilter } It 'Should support Refresh parameter' { From 4d7c0e0f7a2cae6f30fdfbf0ca13ca8975e053c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 19:27:04 +0000 Subject: [PATCH 6/6] Fix FilePath comparison by trimming trailing directory separators Co-authored-by: johlju <7189721+johlju@users.noreply.github.com> --- .../Commands/New-SqlDscAudit.Integration.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 1ee2776752..95745c26b5 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -166,13 +166,13 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName $result.DestinationType | Should -Be 'File' - $result.FilePath | Should -Be $script:testAuditPath + $result.FilePath.TrimEnd('\', '/') | Should -Be $script:testAuditPath.TrimEnd('\', '/') # Verify the audit exists in the server $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop $createdAudit | Should -Not -BeNullOrEmpty $createdAudit.DestinationType | Should -Be 'File' - $createdAudit.FilePath | Should -Be $script:testAuditPath + $createdAudit.FilePath.TrimEnd('\', '/') | Should -Be $script:testAuditPath.TrimEnd('\', '/') } It 'Should create a file audit with maximum file size' {