From e3127b79debaa00a72ddd9768a0beb9901c9b7e8 Mon Sep 17 00:00:00 2001 From: Andreas Jordan Date: Sat, 8 Aug 2026 17:18:04 +0200 Subject: [PATCH] Query Store - Silence the expected warnings of the system database tests The tests added by #10533 assert on their own -WarningVariable but never set -WarningAction, so the warnings they expect still reach the warning stream. A full lab run therefore ended with five warnings that all had to be checked by hand before they could be dismissed as expected. The two calls that are asserted not to warn stay unsilenced, so a regression still shows up as an unexpected warning. (do *QueryStore*) Co-Authored-By: Claude Opus 5 (1M context) --- tests/Get-DbaDbQueryStoreOption.Tests.ps1 | 6 ++++-- tests/Set-DbaDbQueryStoreOption.Tests.ps1 | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Get-DbaDbQueryStoreOption.Tests.ps1 b/tests/Get-DbaDbQueryStoreOption.Tests.ps1 index 68d7b4f6301..d90396f6f08 100644 --- a/tests/Get-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Get-DbaDbQueryStoreOption.Tests.ps1 @@ -34,14 +34,16 @@ Describe $CommandName -Tag IntegrationTests { Context "When a system database is named explicitly" { It "Warns about master and tempdb instead of silently returning nothing" { - $resultsSystemDb = Get-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceSingle -Database master, tempdb -WarningVariable warnSystemDb + $resultsSystemDb = Get-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceSingle -Database master, tempdb -WarningVariable warnSystemDb -WarningAction SilentlyContinue $resultsSystemDb | Should -BeNullOrEmpty $warnSystemDb -join "`n" | Should -Match "Query Store cannot be enabled on system database master" $warnSystemDb -join "`n" | Should -Match "Query Store cannot be enabled on system database tempdb" } It "Reads model from SQL Server 2022 on and warns about it before that" { - $resultsModel = Get-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceSingle -Database model -WarningVariable warnModel + # Silenced because the pre-2022 branch below expects a warning. The warning is still + # captured in $warnModel, so an unexpected one on 2022 and later fails the assertion. + $resultsModel = Get-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceSingle -Database model -WarningVariable warnModel -WarningAction SilentlyContinue if ($serverSingle.VersionMajor -ge 16) { $resultsModel.Database | Should -Be "model" diff --git a/tests/Set-DbaDbQueryStoreOption.Tests.ps1 b/tests/Set-DbaDbQueryStoreOption.Tests.ps1 index 0869eb520f4..d2b4769e4f8 100644 --- a/tests/Set-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Set-DbaDbQueryStoreOption.Tests.ps1 @@ -118,7 +118,7 @@ Describe $CommandName -Tag IntegrationTests { } It "Warns about master and tempdb instead of doing nothing at all" { - $resultsSystemDb = Set-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceMulti1 -Database master, tempdb -State ReadWrite -WarningVariable warnSystemDb + $resultsSystemDb = Set-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceMulti1 -Database master, tempdb -State ReadWrite -WarningVariable warnSystemDb -WarningAction SilentlyContinue $resultsSystemDb | Should -BeNullOrEmpty $warnSystemDb -join "`n" | Should -Match "Query Store cannot be enabled on system database master" $warnSystemDb -join "`n" | Should -Match "Query Store cannot be enabled on system database tempdb" @@ -138,7 +138,7 @@ Describe $CommandName -Tag IntegrationTests { $null = Set-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceMulti1 -Database model -StaleQueryThreshold $originalThreshold } } else { - $resultsModel = Set-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceMulti1 -Database model -StaleQueryThreshold 45 -WarningVariable warnModel + $resultsModel = Set-DbaDbQueryStoreOption -SqlInstance $TestConfig.InstanceMulti1 -Database model -StaleQueryThreshold 45 -WarningVariable warnModel -WarningAction SilentlyContinue $resultsModel | Should -BeNullOrEmpty $warnModel -join "`n" | Should -Match "Query Store cannot be read on model before SQL Server 2022" }