Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing import clixml mocks from dbatools koans #464

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions PSKoans/Koans/Modules/dbatools/AboutBackupDatabases.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Describe "Backup-DbaDatabase" {

[PSCustomObject]@{
ComputerName = 'localhost'
SqlInstance = $ENV:COMPUTERNAME
Database = ('Database_{0:d2}' -f $_)
Type = 'Full'
TotalSize = ('{0}' -f ([Math]::PI * $_))
DeviceType = 'Disk'
Start = $RestoreStart
Duration = $RestoreEnd - $RestoreStart
End = $RestoreEnd
SqlInstance = $ENV:COMPUTERNAME
Database = ('Database_{0:d2}' -f $_)
Type = 'Full'
TotalSize = ('{0}' -f ([Math]::PI * $_))
DeviceType = 'Disk'
Start = $RestoreStart
Duration = $RestoreEnd - $RestoreStart
End = $RestoreEnd
}
$StartDate = $RestoreEnd
}
Expand All @@ -48,14 +48,14 @@ Describe "Backup-DbaDatabase" {

[PSCustomObject]@{
ComputerName = 'localhost'
SqlInstance = $ENV:COMPUTERNAME
Database = ('Database_{0:d2}' -f $_)
Type = 'Full'
TotalSize = ('{0}' -f ([Math]::PI * $_))
DeviceType = 'Disk'
Start = $RestoreStart
Duration = $RestoreEnd - $RestoreStart
End = $RestoreEnd
SqlInstance = $ENV:COMPUTERNAME
Database = ('Database_{0:d2}' -f $_)
Type = 'Full'
TotalSize = ('{0}' -f ([Math]::PI * $_))
DeviceType = 'Disk'
Start = $RestoreStart
Duration = $RestoreEnd - $RestoreStart
End = $RestoreEnd
}

$StartDate = $RestoreEnd
Expand All @@ -68,14 +68,14 @@ Describe "Backup-DbaDatabase" {
$RestoreEnd = $StartDate.AddSeconds(5)
[PSCustomObject]@{
ComputerName = 'localhost'
SqlInstance = $ENV:COMPUTERNAME
Database = 'Database_01'
Type = 'Differential'
TotalSize = ('{0}' -f ([Math]::PI))
DeviceType = 'Disk'
Start = $StartDate
Duration = $RestoreEnd - $StartDate
End = $RestoreEnd
SqlInstance = $ENV:COMPUTERNAME
Database = 'Database_01'
Type = 'Differential'
TotalSize = ('{0}' -f ([Math]::PI))
DeviceType = 'Disk'
Start = $StartDate
Duration = $RestoreEnd - $StartDate
End = $RestoreEnd
}
} -ParameterFilter {
$_.Type -eq 'Differential'
Expand All @@ -85,15 +85,15 @@ Describe "Backup-DbaDatabase" {
$RestoreEnd = $StartDate.AddSeconds(5)
[PSCustomObject]@{
ComputerName = 'localhost'
SqlInstance = $ENV:COMPUTERNAME
Database = 'Database_01'
Type = 'Differential'
TotalSize = ('{0}' -f ([Math]::PI))
DeviceType = 'Disk'
Start = $StartDate
Duration = $RestoreEnd - $StartDate
End = $RestoreEnd
Path = 'E:\Backups\Database_01_201901011200.bak'
SqlInstance = $ENV:COMPUTERNAME
Database = 'Database_01'
Type = 'Differential'
TotalSize = ('{0}' -f ([Math]::PI))
DeviceType = 'Disk'
Start = $StartDate
Duration = $RestoreEnd - $StartDate
End = $RestoreEnd
Path = 'E:\Backups\Database_01_201901011200.bak'
}
} -ParameterFilter {
$_.Path -like 'E:\Backups\*'
Expand All @@ -103,15 +103,15 @@ Describe "Backup-DbaDatabase" {
$RestoreEnd = $StartDate.AddSeconds(5)
[PSCustomObject]@{
ComputerName = 'localhost'
SqlInstance = $ENV:COMPUTERNAME
Database = 'Database_01'
Type = 'Differential'
TotalSize = ('{0}' -f ([Math]::PI))
DeviceType = 'Disk'
Start = $StartDate
Duration = $RestoreEnd - $StartDate
End = $RestoreEnd
Path = 'E:\Backups\Database01-Full.bak'
SqlInstance = $ENV:COMPUTERNAME
Database = 'Database_01'
Type = 'Differential'
TotalSize = ('{0}' -f ([Math]::PI))
DeviceType = 'Disk'
Start = $StartDate
Duration = $RestoreEnd - $StartDate
End = $RestoreEnd
Path = 'E:\Backups\Database01-Full.bak'
}
} -ParameterFilter {
$_.FilePath -eq 'dbname-backuptype.bak'
Expand Down
175 changes: 171 additions & 4 deletions PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,182 @@ Describe 'Get-DbaDatabase' {
#>
BeforeAll {
Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_All.xml
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'testdb'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'LogBackup'
SizeMB = '95.275'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:56:36'
LastDiffBackup = '26/02/2019 13:00:31'
LastLogBackup = '26/02/2019 20:00:02'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'tempdb'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '46.13'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:57:35'
LastDiffBackup = '26/02/2019 13:03:43'
LastLogBackup = '26/02/2019 20:02:57'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'primary'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '29.56'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:59:39'
LastDiffBackup = '26/02/2019 13:01:29'
LastLogBackup = '26/02/2019 20:04:34'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'model'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '39.68'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 20:01:03'
LastDiffBackup = '26/02/2019 13:02:30'
LastLogBackup = '26/02/2019 20:01:19'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'msdb'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '79.29'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:59:54'
LastDiffBackup = '26/02/2019 13:05:07'
LastLogBackup = '26/02/2019 20:04:01'
}
} -ParameterFilter { $_.SqlInstance -eq 'localhost' }

Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_TestDb.xml
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'testdb'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'LogBackup'
SizeMB = '95.275'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:56:36'
LastDiffBackup = '26/02/2019 13:00:31'
LastLogBackup = '26/02/2019 20:00:02'
}
} -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.Database -eq 'testdb' }

Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_System.xml
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'tempdb'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '46.13'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:57:35'
LastDiffBackup = '26/02/2019 13:03:43'
LastLogBackup = '26/02/2019 20:02:57'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'primary'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '29.56'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:59:39'
LastDiffBackup = '26/02/2019 13:01:29'
LastLogBackup = '26/02/2019 20:04:34'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'model'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '39.68'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 20:01:03'
LastDiffBackup = '26/02/2019 13:02:30'
LastLogBackup = '26/02/2019 20:01:19'
},
[PSCustomObject]@{
ComputerName = 'Server01'
InstanceName = 'MSSQLSERVER'
SqlInstance = 'Server01'
Name = 'msdb'
Status = 'Normal'
IsAccessible = 'True'
RecoveryModel = 'Full'
LogReuseWaitStatus = 'Nothing'
SizeMB = '79.29'
Compatibility = 'Version120'
Collation = 'Latin1_General_CI_AS'
Owner = 'sa'
LastFullBackup = '26/02/2019 19:59:54'
LastDiffBackup = '26/02/2019 13:05:07'
LastLogBackup = '26/02/2019 20:04:01'
}
} -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.ExcludeUser }

Mock -CommandName Get-DbaDatabase -MockWith {
Expand Down Expand Up @@ -82,7 +249,7 @@ Describe 'Get-DbaDatabase' {
-ExcludeSystem parameter switch.
#>
$SystemDbParams = @{
SqlInstance = 'localhost'
SqlInstance = 'localhost'
ExludeSystem = ____
}
$SystemDbsExluded = Get-DbaDatabase @SystemDbParams
Expand Down