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

Update tests to be able to run them outside of AppVeyor #9406

Merged
merged 21 commits into from
Jul 1, 2024
Merged
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
9 changes: 4 additions & 5 deletions tests/Backup-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

Context "No database found to backup should raise warning and null output" {
$results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar
$results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar 3> $null
It "Should not return object" {
$results | Should -Be $null
}
Expand Down Expand Up @@ -116,10 +116,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$warnvar | Should -BeLike "*$MissingPath*"
}
# $MissingPathTrailing has a trailing slash but we normalize the path before doing the actual backup
$results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPathTrailing -WarningVariable warnvar -BuildPath
$results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPathTrailing -BuildPath
It "Should have backed up to $MissingPath" {
$results.BackupFolder | Should -Be "$MissingPath"

$results.Path | Should -Not -BeLike '*\\*'
}
}
Expand Down Expand Up @@ -246,9 +245,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

Context "Test Backup-DbaDatabase can take pipe input" {
$results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar
$results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar 3> $null
It "Should not warn" {
'' -eq $warnvar | Should -Be $True
$warnvar | Should -BeNullOrEmpty
}
It "Should Complete Successfully" {
$results.BackupComplete | Should -Be $true
Expand Down
2 changes: 1 addition & 1 deletion tests/Backup-DbaDbCertificate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
It "warns the caller if the cert cannot be found" {
$invalidDBCertName = "dbatoolscli_invalidCertName"
$invalidDBCertName2 = "dbatoolscli_invalidCertName2"
$results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable
$results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null
$null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore
#$results.Certificate | Should -Be $cert2.Name
$warnVariable | Should -BeLike "*Database certificate(s) * not found*"
Expand Down
4 changes: 2 additions & 2 deletions tests/ConvertTo-DbaDataTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ Describe "Testing input parameters" {
}

It "Suppresses warning messages when Silent is used" {
$null = ConvertTo-DbaDataTable -InputObject (returnnull) -IgnoreNull -EnableException -WarningVariable warn -WarningAction SilentlyContinue
$warn.message -eq $null | Should -Be $true
$null = ConvertTo-DbaDataTable -InputObject (returnnull) -IgnoreNull -EnableException -WarningVariable warn -WarningAction SilentlyContinue 3> $null
$warn | Should -BeNullOrEmpty
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Copy-DbaAgentAlert.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
}

It "Skips alerts where destination is missing the operator" {
$results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert2 -WarningVariable warningInfo -WarningAction SilentlyContinue
$results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert2 -WarningAction SilentlyContinue
$results.Status -eq 'Skipped', 'Skipped'
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Copy-DbaBackupDevice.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ if (-not $env:appveyor) {
}
}

$results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue
$results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue 3> $null
if ($warn) {
It "warns if it has a problem moving (issue for local to local)" {
$warn -match "backup device to destination" | Should Be $true
$warn | Should -Match "backup device to destination"
}
} else {
It "should report success" {
Expand Down
2 changes: 1 addition & 1 deletion tests/Copy-DbaCredential.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
It -Skip:(-not $cryptoProvider) "check warning message if crypto provider is not configured/enabled on destination" {
Remove-DbaCredential -SqlInstance $instance3 -Credential dbatoolsci_thor_crypto -Confirm:$false
$instance3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider DISABLE")
$results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thor_crypto -WarningVariable warnings
$results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thor_crypto
$instance3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider ENABLE")
$results.Status | Should Be Failed
$results.Notes | Should -Match "The cryptographic provider $cryptoProvider needs to be configured and enabled on"
Expand Down
8 changes: 3 additions & 5 deletions tests/Copy-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
}

It "Should warn if trying to rename and prefix" {
$results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar
$null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar 3> $null
$warnvar | Should -BeLike "*NewName and Prefix are exclusive options, cannot specify both"

}

It "Should prefix databasename and files" {
Expand Down Expand Up @@ -219,9 +218,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {

$null = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -useDestinationDefaultDirectories
It "Should warn and exit if newname and >1 db specified" {
$prefix = "copy$(Get-Random)"
$results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar
$Warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases"
$null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar 3> $null
$warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases"
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Copy-DbaDbTableData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

It "Should warn if the destinaton table doesn't exist" {
$result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning
$result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$tablewarning | Should -Match Auto
}
Expand All @@ -123,7 +123,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

It "Should warn if the source database doesn't exist" {
$result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning
$result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$tablewarning | Should -Match "cannot open database"
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Copy-DbaDbViewData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

It "Should warn and return nothing if Source and Destination are same" {
$result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning
$result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$tablewarning | Should -match "Cannot copy dbatoolsci_view_example into itself"
}

It "Should warn if the destination table doesn't exist" {
$result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning
$result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$tablewarning | Should -match Auto
}
Expand All @@ -131,7 +131,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

It "Should warn if the source database doesn't exist" {
$result = Copy-DbaDbViewData -SqlInstance $script:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning
$result = Copy-DbaDbViewData -SqlInstance $script:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$tablewarning | Should -match "Failure"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Copy-DbaInstanceTrigger.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}
}

$results = Copy-DbaInstanceTrigger -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue # -ServerTrigger $triggername
$results = Copy-DbaInstanceTrigger -Source $script:instance1 -Destination $script:instance2 -WarningAction SilentlyContinue

It "should report success" {
$results.Status | Should Be "Successful"
Expand Down
2 changes: 1 addition & 1 deletion tests/Copy-DbaRegServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$groupstore.Drop()
}

$results = Copy-DbaRegServer -Source $script:instance2 -Destination $script:instance1 -WarningVariable warn -WarningAction SilentlyContinue -CMSGroup $group
$results = Copy-DbaRegServer -Source $script:instance2 -Destination $script:instance1 -WarningAction SilentlyContinue -CMSGroup $group

It "should report success" {
$results.Status | Should Be "Successful", "Successful"
Expand Down
4 changes: 2 additions & 2 deletions tests/Disable-DbaDbEncryption.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
It "should disable encryption on a database with piping" {
# Give it time to finish encrypting or it'll error
Start-Sleep 10
$results = $db | Disable-DbaDbEncryption -NoEncryptionKeyDrop -WarningVariable warn
$results = $db | Disable-DbaDbEncryption -NoEncryptionKeyDrop -WarningVariable warn 3> $null
$warn | Should -Be $null
$results.EncryptionEnabled | Should -Be $false
}
It "should disable encryption on a database" {
$null = $db | Enable-DbaDbEncryption -EncryptorName $mastercert.Name -Force
# Give it time to finish encrypting or it'll error
Start-Sleep 10
$results = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name -WarningVariable warn
$results = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name -WarningVariable warn 3> $null
$warn | Should -Be $null
$results.EncryptionEnabled | Should -Be $false
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Disable-DbaFilestream.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {

Context "Changing FileStream Level" {
$NewLevel = ($OriginalFileStream.FileStreamStateId + 1) % 3 #Move it on one, but keep it less than 4 with modulo division
$results = Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Force -WarningVariable warnvar -WarningAction silentlyContinue -ErrorVariable errvar -Erroraction silentlyContinue
$results = Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Force -WarningAction silentlyContinue -ErrorVariable errvar -Erroraction silentlyContinue
It "Should have changed the FileStream Level" {
$results.InstanceAccessLevel | Should be $NewLevel
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Dismount-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
}

It "Skips detachment if database is snapshotted" {
$result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn
$result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn 3> $null
$result | Should Be $null
$warn -match "snapshot" | Should Be $true
$result = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db2
Expand Down
4 changes: 2 additions & 2 deletions tests/Get-DbaBackupInformation.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
It "Should be 0 log backups" {
($resultsSanLog | Where-Object {$_.Type -eq 'Transaction Log'}).count | Should be 0
}
$ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue
$ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue 3> $null
It "Should Warn if IgnoreLogBackup without MaintenanceSolution" {
($WarnVar -match "IgnoreLogBackup can only by used with MaintenanceSolution. Will not be used") | Should Be $True
$warnVar | Should -Match "IgnoreLogBackup can only by used with MaintenanceSolution. Will not be used"
}
It "Should ignore IgnoreLogBackup and return 3 backups" {
$resultsSanLog.count | Should Be 3
Expand Down
4 changes: 2 additions & 2 deletions tests/Get-DbaDbAsymmetricKey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force
New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -confirm:$false
New-DbaDbUser -SqlInstance $script:instance2 -Database $database -UserName $dbuser
$key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar
$null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar
$results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database
It "Should Create new key in $database called $keyname" {
$warnvar | Should -BeNullOrEmpty
Expand All @@ -42,7 +42,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$pipeResults | Should -HaveCount 1
}

$key2 = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar
$null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar
$multiResults = Get-DbaDatabase -SqlInstance $script:instance2 -Database $database | Get-DbaDbAsymmetricKey
It "Should return 2 keys" {
$multiResults | Should -HaveCount 2
Expand Down
2 changes: 1 addition & 1 deletion tests/Get-DbaDbBackupHistory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
}

It "Invalid type for -Since" {
$results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since "-" -WarningVariable warning
$results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since "-" -WarningVariable warning 3> $null
$results | Should -BeNullOrEmpty
$warning | Should -BeLike "*-Since must be either a DateTime or TimeSpan object*"
}
Expand Down
12 changes: 8 additions & 4 deletions tests/Get-DbaDbCompatibility.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance1
$compatibilityLevel = $server.Databases['master'].CompatibilityLevel
}
Context "Gets compatibility for multiple databases" {
$results = Get-DbaDbCompatibility -SqlInstance $script:instance1
It "Gets results" {
$results | Should Not Be $null
}
Foreach ($row in $results) {
It "Should return Compatiblity level of Version100 for $($row.database)" {
$row.Compatibility | Should Be "Version100"
It "Should return correct compatibility level for $($row.database)" {
$row.Compatibility | Should Be $compatibilityLevel
$row.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $row.Database).Id
}
}
Expand All @@ -32,8 +36,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
It "Gets results" {
$results | Should Not Be $null
}
It "Should return Compatiblity level of Version100 for $($results.database)" {
$results.Compatibility | Should Be "Version100"
It "Should return correct compatibility level for $($results.database)" {
$results.Compatibility | Should Be $compatibilityLevel
$results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).Id
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Get-DbaDbDetachedFileInfo.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$versionName = $server.GetSqlServerVersionName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't even know this existed, cool.

$random = Get-Random
$dbname = "dbatoolsci_detatch_$random"
$server.Query("CREATE DATABASE $dbname")
Expand All @@ -38,8 +39,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
It "Should be created database" {
$results.name | Should Be $dbname
}
It "Should be 2016" {
$results.version | Should Be 'SQL Server 2016'
It "Should be the correct version" {
$results.version | Should Be $versionName
}
It "Should have Data files" {
$results.DataFiles | Should Not Be $null
Expand Down
Loading
Loading