@@ -16,57 +16,66 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
16
16
Describe " $commandname Integration Tests" - Tags " IntegrationTests" {
17
17
18
18
BeforeAll {
19
- $server = Connect-DbaInstance - SqlInstance $script :instance2
20
- $null = Get-DbaDatabase - SqlInstance $server - Database checkdbTestDatabase | Remove-DbaDatabase - Confirm:$false
21
- $null = Restore-DbaDatabase - SqlInstance $server - Path $script :appveyorlabrepo \sql2008- backups\db1\SQL2008_db1_FULL_20170518_041738.bak - DatabaseName checkdbTestDatabase
22
- $null = New-DbaAgentJob - SqlInstance $server - Job checkdbTestJob
23
- $null = New-DbaAgentJobStep - SqlInstance $server - Job checkdbTestJob - StepName checkdb - Subsystem TransactSql - Command " DBCC CHECKDB('checkdbTestDatabase')"
19
+ $skip = $true
20
+ if ($script :bigDatabaseBackup ) {
21
+ try {
22
+ if (-not (Test-Path - Path $script :bigDatabaseBackup ) -and $script :bigDatabaseBackupSourceUrl ) {
23
+ Invoke-WebRequest - Uri $script :bigDatabaseBackupSourceUrl - OutFile $script :bigDatabaseBackup - ErrorAction Stop
24
+ }
25
+ $null = Restore-DbaDatabase - SqlInstance $script :instance2 - Path $script :bigDatabaseBackup - DatabaseName checkdbTestDatabase - WithReplace - ReplaceDbNameInFile - EnableException
26
+ $null = New-DbaAgentJob - SqlInstance $script :instance2 - Job checkdbTestJob - EnableException
27
+ $null = New-DbaAgentJobStep - SqlInstance $script :instance2 - Job checkdbTestJob - StepName checkdb - Subsystem TransactSql - Command " DBCC CHECKDB('checkdbTestDatabase')" - EnableException
28
+ $skip = $false
29
+ } catch {
30
+ Write-Host - Object " Test for $CommandName failed in BeforeAll because: $_ " - ForegroundColor Cyan
31
+ }
32
+ }
24
33
}
25
34
26
35
AfterAll {
27
- $server = Connect-DbaInstance - SqlInstance $script :instance2
28
- $null = Remove-DbaAgentJob - SqlInstance $server - Job checkdbTestJob - Confirm:$false
29
- $null = Get-DbaDatabase - SqlInstance $erver - Database checkdbTestDatabase | Remove-DbaDatabase - Confirm:$false
36
+ $null = Get-DbaAgentJob - SqlInstance $script :instance2 - Job checkdbTestJob | Remove-DbaAgentJob - Confirm:$false
37
+ $null = Get-DbaDatabase - SqlInstance $script :instance2 - Database checkdbTestDatabase | Remove-DbaDatabase - Confirm:$false
30
38
}
31
39
32
- Context " Gets Query Estimated Completion" {
33
- $server = Connect-DbaInstance - SqlInstance $script :instance2
34
- $null = Start-DbaAgentJob - SqlInstance $server - Job checkdbTestJob
35
- $results = Get-DbaEstimatedCompletionTime - SqlInstance $server
36
- $null = Remove-DbaAgentJob - SqlInstance $server - Job checkdb - Confirm:$false
37
- Start-Sleep - Seconds 5
38
- It " Gets results" {
39
- $results | Should Not Be $null
40
- }
41
- It " Should be SELECT" {
42
- $results.Command | Should Match ' DBCC'
43
- }
44
- It " Should be login dbo" {
45
- $results.login | Should Be ' dbo'
46
- }
47
- }
48
- Context " Gets Query Estimated Completion when using -Database" {
49
- $server = Connect-DbaInstance - SqlInstance $script :instance2
50
- $null = Start-DbaAgentJob - SqlInstance $server - Job checkdbTestJob
51
- $results = Get-DbaEstimatedCompletionTime - SqlInstance $server - Database checkdbTestDatabase
52
- Start-Sleep - Seconds 5
53
- It " Gets results" {
54
- $results | Should Not Be $null
55
- }
56
- It " Should be SELECT" {
57
- $results.Command | Should Match ' DBCC'
40
+ Context " Gets correct results" {
41
+ It - Skip:$skip " Gets Query Estimated Completion" {
42
+ $job = Start-DbaAgentJob - SqlInstance $script :instance2 - Job checkdbTestJob
43
+ Start-Sleep - Seconds 1
44
+ $results = Get-DbaEstimatedCompletionTime - SqlInstance $script :instance2
45
+ while ($job.CurrentRunStatus -eq ' Executing' ) {
46
+ Start-Sleep - Seconds 1
47
+ $job.Refresh ()
48
+ }
49
+
50
+ $results | Should -Not - BeNullOrEmpty
51
+ $results.Command | Should -Match ' DBCC'
52
+ $results.Database | Should - Be checkdbTestDatabase
58
53
}
59
- It " Should be login dbo" {
60
- $results.login | Should Be ' dbo'
54
+
55
+ It - Skip:$skip " Gets Query Estimated Completion when using -Database" {
56
+ $job = Start-DbaAgentJob - SqlInstance $script :instance2 - Job checkdbTestJob
57
+ Start-Sleep - Seconds 1
58
+ $results = Get-DbaEstimatedCompletionTime - SqlInstance $script :instance2 - Database checkdbTestDatabase
59
+ while ($job.CurrentRunStatus -eq ' Executing' ) {
60
+ Start-Sleep - Seconds 1
61
+ $job.Refresh ()
62
+ }
63
+
64
+ $results | Should -Not - BeNullOrEmpty
65
+ $results.Command | Should -Match ' DBCC'
66
+ $results.Database | Should - Be checkdbTestDatabase
61
67
}
62
- }
63
- Context " Gets no Query Estimated Completion when using -ExcludeDatabase" {
64
- $server = Connect-DbaInstance - SqlInstance $script :instance2
65
- $null = Start-DbaAgentJob - SqlInstance $server - Job checkdbTestJob
66
- $results = Get-DbaEstimatedCompletionTime - SqlInstance $server - ExcludeDatabase checkdbTestDatabase
67
- Start-Sleep - Seconds 5
68
- It " Gets no results" {
69
- $results | Should Be $null
68
+
69
+ It - Skip:$skip " Gets no Query Estimated Completion when using -ExcludeDatabase" {
70
+ $job = Start-DbaAgentJob - SqlInstance $script :instance2 - Job checkdbTestJob
71
+ Start-Sleep - Seconds 1
72
+ $results = Get-DbaEstimatedCompletionTime - SqlInstance $script :instance2 - ExcludeDatabase checkdbTestDatabase
73
+ while ($job.CurrentRunStatus -eq ' Executing' ) {
74
+ Start-Sleep - Seconds 1
75
+ $job.Refresh ()
76
+ }
77
+
78
+ $results | Should - BeNullOrEmpty
70
79
}
71
80
}
72
81
}
0 commit comments