@@ -727,6 +727,244 @@ Describe $CommandName -Tag IntegrationTests {
727727 }
728728 }
729729
730+ Context " Additional backup parameters with Default values" {
731+ AfterEach {
732+ Invoke-DbaQuery - SqlInstance $TestConfig.InstanceMulti2 - Query $jobStep.Command - NoExec - EnableException
733+ }
734+
735+ BeforeAll {
736+ $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
737+
738+ # Clean up any leftover test databases from previous runs
739+ $oldTestDbs = Get-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Name -like " dbatoolsci_maintenancesolution_*"
740+ if ($oldTestDbs ) {
741+ $null = Remove-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Database $oldTestDbs.Name - Confirm:$false
742+ }
743+
744+ # Clean up any leftover Hallengren jobs
745+ $oldJobs = Get-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Description -match " hallengren"
746+ if ($oldJobs ) {
747+ $null = Remove-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 - Job $oldJobs.Name - Confirm:$false
748+ }
749+
750+ # Clean up any leftover Hallengren procedures in tempdb from the first Context
751+ $cleanupTempdb = "
752+ IF OBJECT_ID('dbo.CommandExecute', 'P') IS NOT NULL DROP PROCEDURE dbo.CommandExecute;
753+ IF OBJECT_ID('dbo.DatabaseBackup', 'P') IS NOT NULL DROP PROCEDURE dbo.DatabaseBackup;
754+ IF OBJECT_ID('dbo.DatabaseIntegrityCheck', 'P') IS NOT NULL DROP PROCEDURE dbo.DatabaseIntegrityCheck;
755+ IF OBJECT_ID('dbo.IndexOptimize', 'P') IS NOT NULL DROP PROCEDURE dbo.IndexOptimize;
756+ IF OBJECT_ID('dbo.CommandLog', 'U') IS NOT NULL DROP TABLE dbo.CommandLog;
757+ IF OBJECT_ID('dbo.Queue', 'U') IS NOT NULL DROP TABLE dbo.Queue;
758+ IF OBJECT_ID('dbo.QueueDatabase', 'U') IS NOT NULL DROP TABLE dbo.QueueDatabase;
759+ "
760+ $splatCleanupTempdb = @ {
761+ SqlInstance = $TestConfig.InstanceMulti2
762+ Database = " tempdb"
763+ Query = $cleanupTempdb
764+ }
765+ Invoke-DbaQuery @splatCleanupTempdb
766+
767+ $testDbName = " dbatoolsci_maintenancesolution_$ ( Get-Random ) "
768+ $null = New-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Name $testDbName
769+
770+ # Do not pass Compress, Verify, or CheckSum - let them all default to 'Default'
771+ $splatInstall = @ {
772+ SqlInstance = $TestConfig.InstanceMulti2
773+ Database = $testDbName
774+ InstallJobs = $true
775+ ReplaceExisting = $true
776+ CleanupTime = 168
777+ }
778+ $installResult = Install-DbaMaintenanceSolution @splatInstall
779+
780+ # Verify installation succeeded before running tests
781+ # Skip tests if installation failed (eg. due to event log limitations on AppVeyor or SQL Agent not running)
782+ $script :installationSucceeded = $false
783+ if ($installResult ) {
784+ $splatJobCheck = @ {
785+ SqlInstance = $TestConfig.InstanceMulti2
786+ }
787+ $fullBackupJob = Get-DbaAgentJob @splatJobCheck | Where-Object Name -eq " DatabaseBackup - USER_DATABASES - FULL"
788+ if ($fullBackupJob ) {
789+ $script :installationSucceeded = $true
790+ }
791+ }
792+
793+ $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
794+ }
795+
796+ AfterAll {
797+ $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
798+
799+ $null = Remove-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Database $testDbName - Confirm:$false
800+ $jobs = Get-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Description -match " hallengren"
801+ if ($jobs ) {
802+ $null = Remove-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 - Job $jobs.Name - Confirm:$false
803+ }
804+
805+ $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
806+ }
807+
808+ It " Should NOT add Compress parameter to backup jobs" {
809+ if (-not $script :installationSucceeded ) {
810+ Set-ItResult - Skipped - Because " Installation failed"
811+ return
812+ }
813+ $splatJobStep = @ {
814+ SqlInstance = $TestConfig.InstanceMulti2
815+ Job = " DatabaseBackup - USER_DATABASES - FULL"
816+ }
817+ $jobStep = Get-DbaAgentJobStep @splatJobStep
818+ $jobStep.Command | Should -Not -Match " @Compress"
819+ }
820+
821+ It " Should have Verify parameter set to Y in backup jobs" {
822+ if (-not $script :installationSucceeded ) {
823+ Set-ItResult - Skipped - Because " Installation failed"
824+ return
825+ }
826+ $splatJobStep = @ {
827+ SqlInstance = $TestConfig.InstanceMulti2
828+ Job = " DatabaseBackup - USER_DATABASES - FULL"
829+ }
830+ $jobStep = Get-DbaAgentJobStep @splatJobStep
831+ $jobStep.Command | Should -Match " @Verify = 'Y'"
832+ }
833+
834+ It " Should have CheckSum parameter set to Y in backup jobs" {
835+ if (-not $script :installationSucceeded ) {
836+ Set-ItResult - Skipped - Because " Installation failed"
837+ return
838+ }
839+ $splatJobStep = @ {
840+ SqlInstance = $TestConfig.InstanceMulti2
841+ Job = " DatabaseBackup - USER_DATABASES - FULL"
842+ }
843+ $jobStep = Get-DbaAgentJobStep @splatJobStep
844+ $jobStep.Command | Should -Match " @CheckSum = 'Y'"
845+ }
846+ }
847+
848+ Context " Additional backup parameters all removed" {
849+ AfterEach {
850+ Invoke-DbaQuery - SqlInstance $TestConfig.InstanceMulti2 - Query $jobStep.Command - NoExec - EnableException
851+ }
852+
853+ BeforeAll {
854+ $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
855+
856+ # Clean up any leftover test databases from previous runs
857+ $oldTestDbs = Get-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Name -like " dbatoolsci_maintenancesolution_*"
858+ if ($oldTestDbs ) {
859+ $null = Remove-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Database $oldTestDbs.Name - Confirm:$false
860+ }
861+
862+ # Clean up any leftover Hallengren jobs
863+ $oldJobs = Get-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Description -match " hallengren"
864+ if ($oldJobs ) {
865+ $null = Remove-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 - Job $oldJobs.Name - Confirm:$false
866+ }
867+
868+ # Clean up any leftover Hallengren procedures in tempdb from the first Context
869+ $cleanupTempdb = "
870+ IF OBJECT_ID('dbo.CommandExecute', 'P') IS NOT NULL DROP PROCEDURE dbo.CommandExecute;
871+ IF OBJECT_ID('dbo.DatabaseBackup', 'P') IS NOT NULL DROP PROCEDURE dbo.DatabaseBackup;
872+ IF OBJECT_ID('dbo.DatabaseIntegrityCheck', 'P') IS NOT NULL DROP PROCEDURE dbo.DatabaseIntegrityCheck;
873+ IF OBJECT_ID('dbo.IndexOptimize', 'P') IS NOT NULL DROP PROCEDURE dbo.IndexOptimize;
874+ IF OBJECT_ID('dbo.CommandLog', 'U') IS NOT NULL DROP TABLE dbo.CommandLog;
875+ IF OBJECT_ID('dbo.Queue', 'U') IS NOT NULL DROP TABLE dbo.Queue;
876+ IF OBJECT_ID('dbo.QueueDatabase', 'U') IS NOT NULL DROP TABLE dbo.QueueDatabase;
877+ "
878+ $splatCleanupTempdb = @ {
879+ SqlInstance = $TestConfig.InstanceMulti2
880+ Database = " tempdb"
881+ Query = $cleanupTempdb
882+ }
883+ Invoke-DbaQuery @splatCleanupTempdb
884+
885+ $testDbName = " dbatoolsci_maintenancesolution_$ ( Get-Random ) "
886+ $null = New-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Name $testDbName
887+
888+ $splatInstall = @ {
889+ SqlInstance = $TestConfig.InstanceMulti2
890+ Database = $testDbName
891+ InstallJobs = $true
892+ ReplaceExisting = $true
893+ CleanupTime = 168
894+ Compress = " Remove"
895+ Verify = " Remove"
896+ CheckSum = " Remove"
897+ }
898+ $installResult = Install-DbaMaintenanceSolution @splatInstall
899+
900+ # Verify installation succeeded before running tests
901+ # Skip tests if installation failed (eg. due to event log limitations on AppVeyor or SQL Agent not running)
902+ $script :installationSucceeded = $false
903+ if ($installResult ) {
904+ $splatJobCheck = @ {
905+ SqlInstance = $TestConfig.InstanceMulti2
906+ }
907+ $fullBackupJob = Get-DbaAgentJob @splatJobCheck | Where-Object Name -eq " DatabaseBackup - USER_DATABASES - FULL"
908+ if ($fullBackupJob ) {
909+ $script :installationSucceeded = $true
910+ }
911+ }
912+
913+ $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
914+ }
915+
916+ AfterAll {
917+ $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
918+
919+ $null = Remove-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Database $testDbName - Confirm:$false
920+ $jobs = Get-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Description -match " hallengren"
921+ if ($jobs ) {
922+ $null = Remove-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 - Job $jobs.Name - Confirm:$false
923+ }
924+
925+ $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
926+ }
927+
928+ It " Should NOT have Compress parameter in backup jobs" {
929+ if (-not $script :installationSucceeded ) {
930+ Set-ItResult - Skipped - Because " Installation failed"
931+ return
932+ }
933+ $splatJobStep = @ {
934+ SqlInstance = $TestConfig.InstanceMulti2
935+ Job = " DatabaseBackup - USER_DATABASES - FULL"
936+ }
937+ $jobStep = Get-DbaAgentJobStep @splatJobStep
938+ $jobStep.Command | Should -Not -Match " @Compress"
939+ }
940+
941+ It " Should NOT have Verify parameter in backup jobs" {
942+ if (-not $script :installationSucceeded ) {
943+ Set-ItResult - Skipped - Because " Installation failed"
944+ return
945+ }
946+ $splatJobStep = @ {
947+ SqlInstance = $TestConfig.InstanceMulti2
948+ Job = " DatabaseBackup - USER_DATABASES - FULL"
949+ }
950+ $jobStep = Get-DbaAgentJobStep @splatJobStep
951+ $jobStep.Command | Should -Not -Match " @Verify"
952+ }
953+
954+ It " Should NOT have CheckSum parameter in backup jobs" {
955+ if (-not $script :installationSucceeded ) {
956+ Set-ItResult - Skipped - Because " Installation failed"
957+ return
958+ }
959+ $splatJobStep = @ {
960+ SqlInstance = $TestConfig.InstanceMulti2
961+ Job = " DatabaseBackup - USER_DATABASES - FULL"
962+ }
963+ $jobStep = Get-DbaAgentJobStep @splatJobStep
964+ $jobStep.Command | Should -Not -Match " @CheckSum"
965+ }
966+ }
967+
730968 # This case is special. We try to make the install fail.
731969 Context " Backup to Nul with Verify on" {
732970 BeforeAll {
0 commit comments