From c867775cdb49ffd278f56ebd4994d27c1eed14d0 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 9 May 2024 18:17:50 +0200 Subject: [PATCH] Fix Show-SqlBootstrapLog --- ...Install-SqlDscServer.Integration.Tests.ps1 | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index a26f2172a9..0fc15d0a21 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -23,9 +23,59 @@ BeforeDiscovery { } } +BeforeAll { + <# + .SYNOPSIS + This function will output the Setup Bootstrap Summary.txt log file. + + .DESCRIPTION + This function will output the Summary.txt log file, this is to be + able to debug any problems that potentially occurred during setup. + This will pick up the newest Summary.txt log file, so any + other log files will be ignored (AppVeyor build worker has + SQL Server instances installed by default). + This code is meant to work regardless what SQL Server + major version is used for the integration test. + #> + function Show-SqlBootstrapLog + { + [CmdletBinding()] + param + ( + ) + + $summaryLogPath = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server\**\Setup Bootstrap\Log\Summary.txt' | + Sort-Object -Property LastWriteTime -Descending | + Select-Object -First 1 + + $summaryLog = Get-Content $summaryLogPath + + Write-Verbose -Message $('-' * 80) -Verbose + Write-Verbose -Message 'Summary.txt' -Verbose + Write-Verbose -Message $('-' * 80) -Verbose + + $summaryLog | ForEach-Object -Process { + Write-Verbose $_ -Verbose + } + + Write-Verbose -Message $('-' * 80) -Verbose + } +} + Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { Context 'When using Install parameter set' { Context 'When installing database engine default instance' { + AfterAll { + <# + Check if previous It-block failed. If so output the + SQL Server setup log file. + #> + if ( $itBlockError.Count -ne 0 ) + { + Show-SqlBootstrapLog + } + } + It 'Should run the command without throwing' { { # Set splatting parameters for Install-SqlDscServer @@ -43,7 +93,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 Install-SqlDscServer @installSqlDscServerParameters } | Should -Not -Throw - } + } -ErrorVariable itBlockError } } }