Skip to content
Permalink
Browse files

making it prettieer for @CL because she is ace closes #495

  • Loading branch information
SQLDBAWithABeard committed Jul 2, 2019
1 parent de565df commit b2587164a2a61f944defd6ffa0004fa4f06cd0d5

Large diffs are not rendered by default.

@@ -62,7 +62,7 @@ Describe "SQL Agent Account" -Tags AgentServiceAccount, ServiceAccount, $filenam
else {
Context "Testing SQL Agent is running on $psitem" {
@(Get-DbaService -ComputerName $psitem -Type Agent).ForEach{
It "SQL Agent Should Be running on $($psitem.ComputerName)" {
It "SQL Agent should be running on $($psitem.ComputerName)" {
$psitem.State | Should -Be "Running" -Because 'The agent service is required to run SQL Agent jobs'
}
if ($connectioncheck.IsClustered) {
@@ -101,10 +101,10 @@ $ExcludedDatabases += $ExcludeDatabase
if (-not ($destdata)) {$destdata -eq $srv.DefaultFile}
if (-not ($destlog)) {$destlog -eq $srv.DefaultLog}
@(Test-DbaLastBackup -SqlInstance $psitem -Database $dbs -Destination $destserver -DataDirectory $destdata -LogDirectory $destlog -VerifyOnly).ForEach{ if ($psitem.DBCCResult -notmatch "skipped for restored master") {
It "DBCC for $($psitem.Database) on $($psitem.SourceServer) Should Be success" {
It "DBCC for $($psitem.Database) on $($psitem.SourceServer) should be success" {
$psitem.DBCCResult | Should -Be "Success" -Because "You need to run DBCC CHECKDB to ensure your database is consistent"
}
It "restore for $($psitem.Database) on $($psitem.SourceServer) Should Be success" {
It "restore for $($psitem.Database) on $($psitem.SourceServer) should be success" {
$psitem.RestoreResult | Should -Be "Success" -Because "The backup file has not successfully restored - you have no backup"
}
}
@@ -196,7 +196,7 @@ $ExcludedDatabases += $ExcludeDatabase
Context "Testing Last Good DBCC CHECKDB on $psitem" {
@(Get-DbaLastGoodCheckDb -SqlInstance $psitem -Database ((Connect-DbaInstance -SqlInstance $psitem).Databases.Where{$_.CreateDate -lt (Get-Date).AddHours( - $graceperiod) -and ($_.IsAccessible -eq $true) -and $(if ($database) {$psitem.name -in $Database}else {$ExcludedDatabases -notcontains $_.Name})}).Name ).ForEach{
if ($psitem.Database -ne "tempdb") {
It "last good integrity check for $($psitem.Database) on $($psitem.SqlInstance) Should Be less than $maxdays days old" {
It "last good integrity check for $($psitem.Database) on $($psitem.SqlInstance) should be less than $maxdays days old" {
$psitem.LastGoodCheckDb | Should -BeGreaterThan (Get-Date).AddDays( - ($maxdays)) -Because "You should have run a DBCC CheckDB inside that time"
}
It -Skip:$datapurity "last good integrity check for $($psitem.Database) on $($psitem.SqlInstance) has Data Purity Enabled" {
@@ -224,7 +224,7 @@ $ExcludedDatabases += $ExcludeDatabase
@(Test-DbaIdentityUsage -SqlInstance $psitem -Database $Database -ExcludeDatabase $exclude).ForEach{
if ($psitem.Database -ne "tempdb") {
$columnfqdn = "$($psitem.Database).$($psitem.Schema).$($psitem.Table).$($psitem.Column)"
It "usage for $columnfqdn on $($psitem.SqlInstance) Should Be less than $maxpercentage percent" {
It "usage for $columnfqdn on $($psitem.SqlInstance) should be less than $maxpercentage percent" {
$psitem.PercentUsed -lt $maxpercentage | Should -BeTrue -Because "You do not want your Identity columns to hit the max value and stop inserts"
}
}
@@ -441,7 +441,7 @@ $ExcludedDatabases += $ExcludeDatabase
Context "Testing last full backups on $psitem" {
$Instance.Databases.Where{ ($psitem.Name -ne 'tempdb') -and $Psitem.CreateDate -lt (Get-Date).AddHours( - $graceperiod) -and $(if ($Database) {$PsItem.Name -in $Database}else {$ExcludedDatabases -notcontains $PsItem.Name})}.ForEach{
$skip = ($psitem.Status -match "Offline") -or ($psitem.IsAccessible -eq $false) -or ($psitem.Readonly -eq $true -and $skipreadonly -eq $true)
It -Skip:$skip "$($psitem.Name) full backups on $($psitem.Parent.Name) Should Be less than $maxfull days" {
It -Skip:$skip "$($psitem.Name) full backups on $($psitem.Parent.Name) should be less than $maxfull days" {
$psitem.LastBackupDate | Should -BeGreaterThan (Get-Date).AddDays( - ($maxfull)) -Because "Taking regular backups is extraordinarily important"
}
}
@@ -465,7 +465,7 @@ $ExcludedDatabases += $ExcludeDatabase
Context "Testing last diff backups on $psitem" {
@((Connect-DbaInstance -SqlInstance $psitem).Databases.Where{ (-not $psitem.IsSystemObject) -and $Psitem.CreateDate -lt (Get-Date).AddHours( - $graceperiod) -and $(if ($Database) {$PsItem.Name -in $Database}else {$ExcludedDatabases -notcontains $PsItem.Name})}).ForEach{
$skip = ($psitem.Status -match "Offline") -or ($psitem.IsAccessible -eq $false) -or ($psitem.Readonly -eq $true -and $skipreadonly -eq $true)
It -Skip:$skip "$($psitem.Name) diff backups on $($psitem.Parent.Name) Should Be less than $maxdiff hours" {
It -Skip:$skip "$($psitem.Name) diff backups on $($psitem.Parent.Name) should be less than $maxdiff hours" {
$psitem.LastDifferentialBackupDate | Should -BeGreaterThan (Get-Date).AddHours( - ($maxdiff)) -Because 'Taking regular backups is extraordinarily important'
}
}
@@ -490,7 +490,7 @@ $ExcludedDatabases += $ExcludeDatabase
@((Connect-DbaInstance -SqlInstance $psitem).Databases.Where{ (-not $psitem.IsSystemObject) -and $Psitem.CreateDate -lt (Get-Date).AddHours( - $graceperiod) -and $(if ($Database) {$PsItem.Name -in $Database}else {$ExcludedDatabases -notcontains $PsItem.Name})}).ForEach{
if ($psitem.RecoveryModel -ne "Simple") {
$skip = ($psitem.Status -match "Offline") -or ($psitem.IsAccessible -eq $false) -or ($psitem.Readonly -eq $true -and $skipreadonly -eq $true)
It -Skip:$skip "$($psitem.Name) log backups on $($psitem.Parent.Name) Should Be less than $maxlog minutes" {
It -Skip:$skip "$($psitem.Name) log backups on $($psitem.Parent.Name) should be less than $maxlog minutes" {
$psitem.LastLogBackupDate | Should -BeGreaterThan (Get-Date).AddMinutes( - ($maxlog) + 1) -Because "Taking regular backups is extraordinarily important"
}
}
@@ -511,7 +511,7 @@ $ExcludedDatabases += $ExcludeDatabase
else {
Context "Testing Database VLFs on $psitem" {
@(Test-DbaDbVirtualLogFile -SqlInstance $psitem -ExcludeDatabase $ExcludedDatabases -Database $Database).ForEach{
It "$($psitem.Database) VLF count on $($psitem.SqlInstance) Should Be less than $vlfmax" {
It "$($psitem.Database) VLF count on $($psitem.SqlInstance) should be less than $vlfmax" {
$psitem.Total | Should -BeLessThan $vlfmax -Because "Too many VLFs can impact performance and slow down backup/restore"
}
}
@@ -5,12 +5,12 @@ Describe "Active Directory Domain Name" -Tags DomainName, $filename {
@(Get-ComputerName).ForEach{
Context "Testing Active Directory Domain Name on $psitem" {
if ($IsLinux) {
It "$psitem Should Be on the Domain $domain - running on Linux so cant check AD for now" -Skip {
It "$psitem should be on the Domain $domain - running on Linux so cant check AD for now" -Skip {
(Get-DbaCmObject -Class Win32_ComputerSystem -ComputerName $psitem -Credential $credential).Domain | Should -Be $domain -Because 'The machine needs to be on the domain'
}
}
else {
It "$psitem Should Be on the Domain $domain" {
It "$psitem should be on the Domain $domain" {
(Get-DbaCmObject -Class Win32_ComputerSystem -ComputerName $psitem -Credential $credential).Domain | Should -Be $domain -Because 'The machine needs to be on the domain'
}
}
@@ -24,7 +24,7 @@ Describe "Active Directory OU" -Tags OrganizationalUnit, $filename {
@(Get-ComputerName).ForEach{
if ($IsLinux) {
Context "Testing Active Directory OU on $psitem" {
It "$psitem Should Be on the Domain $domain - running on Linux so cant check AD for now" -Skip {
It "$psitem should be on the Domain $domain - running on Linux so cant check AD for now" -Skip {
(Get-DbaCmObject -Class Win32_ComputerSystem -ComputerName $psitem -Credential $credential).Domain | Should -Be $domain -Because 'The machine needs to be on the domain'
}
}
@@ -35,7 +35,7 @@ Describe "Active Directory OU" -Tags OrganizationalUnit, $filename {
# Can be passed by Invoke-DbcCheck -Value
$value = Get-DbcConfigValue domain.organizationalunit
}
It -Skip "$psitem Should Be in the right OU ($value)" {
It -Skip "$psitem should be in the right OU ($value)" {
(Get-ADComputer $psitem -Properties CanonicalName -Server $dc).CanonicalName | Should -Be $value -Because 'The SQL Server should be in the correct OU'
}
}
@@ -141,7 +141,7 @@ foreach ($clustervm in $clusters) {

@($AG.AvailabilityReplicas).ForEach{
$results = Test-DbaConnection -sqlinstance $PsItem.Name
It "Replica $($results.SqlInstance) Should Be Pingable" {
It "Replica $($results.SqlInstance) should be Pingable" {
$results.IsPingable | Should -BeTrue -Because 'Each replica should be pingable'
}
It "Replica $($results.SqlInstance) should be able to connect with SQL" {
@@ -50,11 +50,11 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
}
#local is always NTLM except when its a container ;-)
if($InstanceSMO.NetBiosName -eq $ENV:COMPUTERNAME -and ($instance -notlike '*,*')){
It -Skip:$skipauth "auth scheme Should Be NTLM on the local machine on $psitem" {
It -Skip:$skipauth "auth scheme should be NTLM on the local machine on $psitem" {
(Test-DbaConnectionAuthScheme -SqlInstance $Instance).authscheme| Should -Be NTLM
}
}else{
It -Skip:$skipauth "auth scheme Should Be $authscheme on $psitem" {
It -Skip:$skipauth "auth scheme should be $authscheme on $psitem" {
(Test-DbaConnectionAuthScheme -SqlInstance $Instance).authscheme | Should -Be $authscheme
}
}
@@ -219,7 +219,7 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
else {
Context "Testing Network Latency on $psitem" {
@(Test-DbaNetworkLatency -SqlInstance $psitem).ForEach{
It "network latency Should Be less than $max ms on $($psitem.SqlInstance)" {
It "network latency should be less than $max ms on $($psitem.SqlInstance)" {
$psitem.Average.TotalMilliseconds | Should -BeLessThan $max -Because 'You do not want to be waiting on the network'
}
}
@@ -257,13 +257,13 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
else {
Context "Testing Max Memory on $psitem" {
if (-not $IsLInux){
It "Max Memory setting Should Be correct on $psitem" {
It "Max Memory setting should be correct on $psitem" {
@(Test-DbaMaxMemory -SqlInstance $psitem).ForEach{
$psitem.SqlMaxMB | Should -BeLessThan ($psitem.RecommendedMB + 379) -Because 'You do not want to exhaust server memory'
}
}
}else {
It "Max Memory setting Should Be correct (running on Linux so only checking Max Memory is less than Total Memory) on $psitem" {
It "Max Memory setting should be correct (running on Linux so only checking Max Memory is less than Total Memory) on $psitem" {
# simply check that the max memory is less than total memory
$MemoryValues = Get-DbaMaxMemory -SqlInstance $psitem
$MemoryValues.Total | Should -BeGreaterThan $MemoryValues.MaxValue -Because 'You do not want to exhaust server memory'
@@ -400,7 +400,7 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
}
}

Describe "XE Sessions That Should Be Stopped" -Tags XESessionStopped, ExtendedEvent, Medium, $filename {
Describe "XE Sessions That should be Stopped" -Tags XESessionStopped, ExtendedEvent, Medium, $filename {
$xesession = Get-DbcConfigValue policy.xevent.requiredstoppedsession
# no point running if we dont have something to check
if ($xesession) {
@@ -427,7 +427,7 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
}
}

Describe "XE Sessions That Should Be Running" -Tags XESessionRunning, ExtendedEvent, Medium, $filename {
Describe "XE Sessions That should be Running" -Tags XESessionRunning, ExtendedEvent, Medium, $filename {
$xesession = Get-DbcConfigValue policy.xevent.requiredrunningsession
# no point running if we dont have something to check
if ($xesession) {
@@ -442,7 +442,7 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
Context "Checking running sessions on $psitem" {
$runningsessions = (Get-DbaXESession -SqlInstance $psitem).Where{$_.Status -eq 'Running'}.Name
@($xesession).ForEach{
It "session $psitem Should Be running on $Instance" {
It "session $psitem should be running on $Instance" {
$psitem | Should -BeIn $runningsessions -Because "$psitem session should be running"
}
}
@@ -807,20 +807,20 @@ Describe "SQL Browser Service" -Tags SqlBrowserServiceAccount, ServiceAccount, H
if(-not $IsLinux){
$Services = Get-DbaService -ComputerName $psitem
if ($Services.Where{$_.ServiceType -eq 'Engine'}.Count -eq 1) {
It "SQL browser service on $psitem Should Be Stopped as only one instance is installed" {
It "SQL browser service on $psitem should be Stopped as only one instance is installed" {
$Services.Where{$_.ServiceType -eq 'Browser'}.State | Should -Be "Stopped" -Because 'Unless there are multple instances you dont need the browser service'
}
}
else {
It "SQL browser service on $psitem Should Be Running as multiple instances are installed" {
It "SQL browser service on $psitem should be Running as multiple instances are installed" {
$Services.Where{$_.ServiceType -eq 'Browser'}.State| Should -Be "Running" -Because 'You need the browser service with multiple instances' }
}
if ($Services.Where{$_.ServiceType -eq 'Engine'}.Count -eq 1) {
It "SQL browser service startmode Should Be Disabled on $psitem as only one instance is installed" {
It "SQL browser service startmode should be Disabled on $psitem as only one instance is installed" {
$Services.Where{$_.ServiceType -eq 'Browser'}.StartMode | Should -Be "Disabled" -Because 'Unless there are multple instances you dont need the browser service' }
}
else {
It "SQL browser service startmode Should Be Automatic on $psitem as multiple instances are installed" {
It "SQL browser service startmode should be Automatic on $psitem as multiple instances are installed" {
$Services.Where{$_.ServiceType -eq 'Browser'}.StartMode | Should -Be "Automatic"
}
}
@@ -3,7 +3,7 @@ Describe "Log Shipping Status Primary" -Tags LogShippingPrimary, $filename {
@(Get-Instance).ForEach{
Context "Testing the primary databases on $psitem" {
@(Test-DbaDbLogShipStatus -SqlInstance $psitem -Primary).ForEach{
It "Status Should Be OK for $($psitem.Database) on $($psitem.SqlInstance)" {
It "Status should be OK for $($psitem.Database) on $($psitem.SqlInstance)" {
$psitem.Status | Should -Be "All OK" -Because 'The Log shipping should be ok'
}
}
@@ -14,7 +14,7 @@ Describe "Log Shipping Status Secondary" -Tags LogShippingSecondary, $filename {
@(Get-Instance).ForEach{
Context "Testing the secondary databases on $psitem" {
@(Test-DbaDbLogShipStatus -SqlInstance $psitem -Secondary).ForEach{
It "Status Should Be OK for $($psitem.Database) on $($psitem.SqlInstance)" {
It "Status should be OK for $($psitem.Database) on $($psitem.SqlInstance)" {
$psitem.Status | Should -Be "All OK" -Because 'The Log shipping should be ok'
}
}

0 comments on commit b258716

Please sign in to comment.
You can’t perform that action at this time.