@@ -1265,4 +1265,147 @@ Describe $CommandName -Tag IntegrationTests {
12651265 $jobStep.Command | Should -Match " @CheckSum = 'Y'"
12661266 }
12671267 }
1268+
1269+ Context " Defaults for unspecified parameters are as documentation says" {
1270+ BeforeAll {
1271+ $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
1272+
1273+ # Clean up any leftover test databases from previous runs
1274+ $oldTestDbs = Get-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Name -like " dbatoolsci_maintenancesolution_*"
1275+ if ($oldTestDbs ) {
1276+ $null = Remove-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Database $oldTestDbs.Name - Confirm:$false
1277+ }
1278+
1279+ # Clean up any leftover Hallengren jobs
1280+ $oldJobs = Get-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Description -match " hallengren"
1281+ if ($oldJobs ) {
1282+ $null = Remove-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 - Job $oldJobs.Name - Confirm:$false
1283+ }
1284+
1285+ # Clean up any leftover Hallengren procedures in tempdb from the first Context
1286+ $cleanupTempdb = "
1287+ IF OBJECT_ID('dbo.CommandExecute', 'P') IS NOT NULL DROP PROCEDURE dbo.CommandExecute;
1288+ IF OBJECT_ID('dbo.DatabaseBackup', 'P') IS NOT NULL DROP PROCEDURE dbo.DatabaseBackup;
1289+ IF OBJECT_ID('dbo.DatabaseIntegrityCheck', 'P') IS NOT NULL DROP PROCEDURE dbo.DatabaseIntegrityCheck;
1290+ IF OBJECT_ID('dbo.IndexOptimize', 'P') IS NOT NULL DROP PROCEDURE dbo.IndexOptimize;
1291+ IF OBJECT_ID('dbo.CommandLog', 'U') IS NOT NULL DROP TABLE dbo.CommandLog;
1292+ IF OBJECT_ID('dbo.Queue', 'U') IS NOT NULL DROP TABLE dbo.Queue;
1293+ IF OBJECT_ID('dbo.QueueDatabase', 'U') IS NOT NULL DROP TABLE dbo.QueueDatabase;
1294+ "
1295+ $splatCleanupTempdb = @ {
1296+ SqlInstance = $TestConfig.InstanceMulti2
1297+ Database = " tempdb"
1298+ Query = $cleanupTempdb
1299+ }
1300+ Invoke-DbaQuery @splatCleanupTempdb
1301+
1302+ $testDbName = " dbatoolsci_maintenancesolution_$ ( Get-Random ) "
1303+ $null = New-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Name $testDbName
1304+
1305+ $splatInstall = @ {
1306+ SqlInstance = $TestConfig.InstanceMulti2
1307+ # We could test that the default database is master,
1308+ # but that is currently enforced at the PowerShell level
1309+ # so it could just be a unit test.
1310+ Database = $testDbName
1311+ InstallJobs = $true
1312+ ReplaceExisting = $true
1313+ AutoScheduleJobs = " WeeklyFull"
1314+ }
1315+ $installResult = Install-DbaMaintenanceSolution @splatInstall
1316+
1317+ # Verify installation succeeded before running tests
1318+ # Skip tests if installation failed (eg. due to event log limitations on AppVeyor or SQL Agent not running)
1319+ $script :installationSucceeded = $false
1320+ if ($installResult ) {
1321+ $splatJobCheck = @ {
1322+ SqlInstance = $TestConfig.InstanceMulti2
1323+ }
1324+ $fullBackupJob = Get-DbaAgentJob @splatJobCheck | Where-Object Name -eq " DatabaseBackup - USER_DATABASES - FULL"
1325+ if ($fullBackupJob ) {
1326+ $script :installationSucceeded = $true
1327+ }
1328+ }
1329+
1330+ $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
1331+ }
1332+
1333+ AfterAll {
1334+ $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
1335+
1336+ $null = Remove-DbaDatabase - SqlInstance $TestConfig.InstanceMulti2 - Database $testDbName - Confirm:$false
1337+ $jobs = Get-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 | Where-Object Description -match " hallengren"
1338+ if ($jobs ) {
1339+ $null = Remove-DbaAgentJob - SqlInstance $TestConfig.InstanceMulti2 - Job $jobs.Name - Confirm:$false
1340+ }
1341+
1342+ $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
1343+ }
1344+
1345+ It " Should NOT have Compress parameter in backup jobs" {
1346+ if (-not $script :installationSucceeded ) {
1347+ Set-ItResult - Skipped - Because " Installation failed"
1348+ return
1349+ }
1350+ $splatJobStep = @ {
1351+ SqlInstance = $TestConfig.InstanceMulti2
1352+ Job = " DatabaseBackup - USER_DATABASES - FULL"
1353+ }
1354+ $jobStep = Get-DbaAgentJobStep @splatJobStep
1355+ $jobStep.Command | Should -Not -Match " @Compress"
1356+ }
1357+
1358+ It " Should have Verify parameter set to Y in backup jobs" {
1359+ if (-not $script :installationSucceeded ) {
1360+ Set-ItResult - Skipped - Because " Installation failed"
1361+ return
1362+ }
1363+ $splatJobStep = @ {
1364+ SqlInstance = $TestConfig.InstanceMulti2
1365+ Job = " DatabaseBackup - USER_DATABASES - FULL"
1366+ }
1367+ $jobStep = Get-DbaAgentJobStep @splatJobStep
1368+ $jobStep.Command | Should -Match " @Verify = 'Y'"
1369+ }
1370+
1371+ It " Should have CheckSum parameter set to Y in backup jobs" {
1372+ if (-not $script :installationSucceeded ) {
1373+ Set-ItResult - Skipped - Because " Installation failed"
1374+ return
1375+ }
1376+ $splatJobStep = @ {
1377+ SqlInstance = $TestConfig.InstanceMulti2
1378+ Job = " DatabaseBackup - USER_DATABASES - FULL"
1379+ }
1380+ $jobStep = Get-DbaAgentJobStep @splatJobStep
1381+ $jobStep.Command | Should -Match " @CheckSum = 'Y'"
1382+ }
1383+
1384+ It " Should have StartTime set to 011500 in backup schedule" {
1385+ if (-not $script :installationSucceeded ) {
1386+ Set-ItResult - Skipped - Because " Installation failed"
1387+ return
1388+ }
1389+ $schedule = Get-DbaAgentSchedule - SqlInstance $TestConfig.InstanceMulti2
1390+ # We do not make any promises about job names,
1391+ # so checking for times is all we can do.
1392+ $schedule.ActiveStartTimeOfDay |
1393+ Where-Object { $_.Hours -eq 1 -and $_.Minutes -eq 15 } |
1394+ Should -Not - BeNullOrEmpty
1395+ }
1396+
1397+ It " Should have BackupLocation parameter set to instance default in backup jobs" {
1398+ if (-not $script :installationSucceeded ) {
1399+ Set-ItResult - Skipped - Because " Installation failed"
1400+ return
1401+ }
1402+ $splatJobStep = @ {
1403+ SqlInstance = $TestConfig.InstanceMulti2
1404+ Job = " DatabaseBackup - USER_DATABASES - FULL"
1405+ }
1406+ $jobStep = Get-DbaAgentJobStep @splatJobStep
1407+ $backupLocationSetting = (Get-DbaDefaultPath - SqlInstance $TestConfig.InstanceMulti2 ).Backup
1408+ $jobStep.Command | Should - BeLike " *@Directory = *$backupLocationSetting *"
1409+ }
1410+ }
12681411}
0 commit comments