Skip to content

Add public command Get-SqlDscSetupLog to retrieve SQL Server setup bootstrap logs #2311

@coderabbitai

Description

@coderabbitai

Description

Extract the duplicated error handling logic from integration tests into a new public command that retrieves SQL Server setup bootstrap logs (Summary.txt).

Background

Currently, the error handling block that outputs Summary.txt content is duplicated across multiple integration tests. For example, in the Initialize-SqlDscRebuildDatabase integration test, this pattern appears three times (lines 95-120, 169-194, 225-250).

Proposal

Create a new public command Get-SqlDscSetupLog that:

  • Retrieves the SQL Server setup bootstrap log (Summary.txt)
  • Can be used interactively by users
  • Accepts parameters to control behavior (e.g., path and filename) with sensible default values
  • Can be reused across all integration tests needing this functionality

Example implementation structure:

function Get-SqlDscSetupLog
{
    [CmdletBinding()]
    param (
        [Parameter()]
        [System.String]
        $Path = 'C:\Program Files\Microsoft SQL Server',

        [Parameter()]
        [System.String]
        $FileName = 'Summary.txt'
    )

    $summaryFiles = Get-ChildItem -Path $Path -Filter $FileName -Recurse -ErrorAction 'SilentlyContinue' |
        Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } |
        Sort-Object -Property 'LastWriteTime' -Descending |
        Select-Object -First 1

    if ($summaryFiles)
    {
        "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====="
        Get-Content -Path $summaryFiles.FullName
        "==== End of Summary.txt ====="
    }
    else
    {
        'No Summary.txt file found.'
    }
}

Usage in integration tests:

catch
{
    Write-Verbose -Message (Get-SqlDscSetupLog) -Verbose
    throw $_
}

Tasks

  • Create the public command Get-SqlDscSetupLog with appropriate parameters
  • Add unit tests for the new command
  • Update integration tests to use the new command (Initialize-SqlDscRebuildDatabase and others)
  • Add command documentation
  • Update CHANGELOG.md

References

Requested by: @johlju

Metadata

Metadata

Assignees

Labels

enhancementThe issue is an enhancement request.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions