forked from dataplat/dbatools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DbaLastBackup.Tests.ps1
48 lines (41 loc) · 1.84 KB
/
Get-DbaLastBackup.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$commandname = $MyInvocation.MyCommand.Name.Replace(".ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaSqlServer -SqlInstance $script:instance2
$random = Get-Random
$dbname = "dbatoolsci_getlastbackup$random"
$server.Query("CREATE DATABASE $dbname")
$server.Query("ALTER DATABASE $dbname SET RECOVERY FULL WITH NO_WAIT")
}
AfterAll {
$null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase
}
Context "Get null history for database" {
$results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname
It "doesn't have any values for last backups because none exist yet" {
$results.LastFullBackup | Should Be $null
$results.LastDiffBackup | Should Be $null
$results.LastLogBackup | Should Be $null
}
}
$yesterday = (Get-Date).AddDays(-1)
Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase
Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -Type Differential
Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -Type Log
Context "Get last history for single database" {
$results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname
It "returns a date within the proper range" {
[datetime]$results.LastFullBackup -gt $yesterday | Should Be $true
[datetime]$results.LastDiffBackup -gt $yesterday | Should Be $true
[datetime]$results.LastLogBackup -gt $yesterday | Should Be $true
}
}
Context "Get last history for all databases" {
$results = Get-DbaLastBackup -SqlInstance $script:instance2
It "returns more than 3 databases" {
$results.count -gt 3 | Should Be $true
}
}
}