Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 18, 2025

Create integration test for New-SqlDscAudit command

Plan

Based on my exploration of the repository structure and existing integration tests, I need to implement the following to address the issue:

  • Analyze the codebase structure and existing patterns
  • Review the New-SqlDscAudit command functionality
  • Examine existing integration test patterns (like Remove-SqlDscAudit.Integration.Tests.ps1)
  • Identify the correct integration test group for the new test
  • Create New-SqlDscAudit.Integration.Tests.ps1 following established patterns
  • Add comprehensive test scenarios covering different parameter sets
  • Update the Azure pipelines configuration to include the new test
  • Validate the integration test works properly
  • Update documentation (CHANGELOG.md and README.md)
  • Address feedback: Add PassThru parameter, fix error message, ensure proper file ending
  • Fix integration test runtime issues: SQL Server accessible path and ReserveDiskSpace parameters
  • Fix AuditFilter test to handle SQL Server expression normalization
  • Fix FilePath comparison to handle directory separator normalization

Implementation Details

Integration Test Coverage

The new integration test (New-SqlDscAudit.Integration.Tests.ps1) provides comprehensive coverage for:

  1. Application Log Audits: Creating audits that write to Windows Application Log
  2. Security Log Audits: Creating audits that write to Windows Security Log
  3. File Audits: Creating audits that write to file system with various configurations:
    • Basic file audits
    • File audits with maximum file size settings
    • File audits with maximum files and disk space reservation
    • File audits with rollover file limits
  4. Advanced Options: Testing audit creation with:
    • OnFailure behavior settings
    • QueueDelay configurations
    • Custom AuditGuid values
    • AuditFilter expressions (with SQL Server normalization handling)
    • Refresh parameter support
  5. Pipeline Support: Testing pipeline input with ServerObject
  6. Error Handling: Testing error conditions like duplicate audit names and invalid paths
  7. PassThru Parameter: Verifying audit object is returned when requested

Recent Updates (Latest Commit)

  • Fixed FilePath comparison: Added .TrimEnd('\', '/') to both the actual and expected FilePath values before comparison. SQL Server normalizes file paths by adding trailing directory separators, so the test now handles this normalization properly.

Previous Updates

  • Fixed AuditFilter test: Updated to expect SQL Server normalized filter expression ([database_name]='master') instead of the input expression ([database_name] = 'master'). SQL Server automatically removes spaces around operators when storing filter expressions.
  • Fixed audit path: Changed from $env:TEMP to C:\Temp\SqlDscTestAudits to ensure SQL Server service can access the location
  • Fixed ReserveDiskSpace test: Added required -MaximumFileSize and -MaximumFileSizeUnit parameters when using -ReserveDiskSpace to comply with SQL Server requirements (RESERVE_DISK_SPACE cannot be used with MAXSIZE = UNLIMITED)
  • Added -PassThru parameter to all New-SqlDscAudit invocations where a return value is expected, ensuring proper object return
  • Fixed error message to reference the correct build task (noop instead of build)
  • Ensured proper file ending with exactly one blank line as per project standards

Pipeline Integration

  • Added the test to Group 2 in azure-pipelines.yml in the appropriate alphabetical position
  • Group 2 is correct as it contains commands that create objects but don't depend on other tests

Documentation Updates

  • Updated CHANGELOG.md to document the new integration test
  • Updated tests/Integration/Commands/README.md to include the new test in the dependency table

Validation

  • Build succeeded with all changes
  • PowerShell syntax validation passed
  • Pester discovered 15 test cases in the new file
  • All changes follow the established patterns from existing integration tests
  • Integration test issues identified in CI runs have been progressively addressed
  • Handles SQL Server normalization behaviors for both filter expressions and file paths

Fixes #2226.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

Copilot AI changed the title [WIP] Integration test missing for New-SqlDscAudit Add integration test for New-SqlDscAudit command Sep 18, 2025
Copilot AI requested a review from johlju September 18, 2025 10:36
@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (52e707f) to head (4d7c0e0).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2257   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files       149     149           
  Lines      9163    9163           
====================================
  Hits       8687    8687           
  Misses      476     476           
Flag Coverage Δ
unit 94% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link

coderabbitai bot commented Sep 21, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI requested a review from johlju September 21, 2025 16:17
@johlju johlju marked this pull request as ready for review September 21, 2025 16:17
@johlju johlju requested a review from a team as a code owner September 21, 2025 16:17
…equired parameters for ReserveDiskSpace

Co-authored-by: johlju <[email protected]>
Copilot AI requested a review from johlju September 21, 2025 19:28
@johlju johlju merged commit e3c32b5 into main Sep 22, 2025
27 checks passed
@johlju johlju deleted the copilot/fix-2226 branch September 22, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration test missing for New-SqlDscAudit

2 participants