Skip to content

Guide for Vendor Tests

Rob Sewell edited this page Feb 20, 2018 · 5 revisions

SQL Server Vendors, we're happy to include your Tests in our module 👍

dbachecks is a framework created by and for SQL Server pros who need to validate their environments. Basically, we all share similar checklists and mostly just the server names and RPO/RTO/etc change.

You can make use of our framework to enable SQL Server Professionals to quickly and easily test that your product has been set up in the manner that you expect. For example, you might wish to ensure that services have been started or set to automatic start, that correct permissions have been applied to service accounts or that supported versions are installed.

Note

Vendor checks are for vendor-specific checks. If you have a general check that would benefit the community, please add it to the regular test files (Database.Tests.ps1, Agent.Tests.ps1, etc)

To join in, create a file in \checks called YourName.Tests.ps1. So if your company name is Acme, then name your test file Acme.Tests.ps1.

Follow the dbachecks developer guide and add your tests. Here is a sample Vendor check

# ensure you keep this here, it automatically tags your test Group
$filename = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")

# if you have a custom module, ensure the user can load it
try {
	Import-Module AcmeBackups -ErrorAction Stop
}
catch {
	Stop-PSFFunction -Message "AcmeBackups module could not load" -ErrorRecord $psitem
	return
}

# If your test connects to a Windows server, use the internal command Get-ComputerName to get the computer collection
Describe "Acme Services" -Tags AcmeService, $filename {
	(Get-ComputerName).ForEach{
		Context "Testing Acme Backup Service is running on $psitem" {
			(Get-AcmeService -ComputerName $psitem -Type Engine).ForEach{
				It "Acme Service should be running" {
					$psitem.State | Should -Be "Running"
				}
				It "Acme Service should have a start mode of Automatic" {
					$psitem.StartMode | Should -Be "Automatic"
				}
			}
		}
	}
}

# If your test connects to a SQL Server, use the internal command Get-SqlInstance to get the computer collection
Describe "Acme Stored Procedures" -Tags AcmeStordProceure, $filename {
	(Get-SqlInstance).ForEach{
		Context "Testing Acme admin stored procedures exist on $psitem" {
			$results = Get-AcmeAdminSp -SqlInstance $psitem -Database dbadb
			It "5 sprocs should be returned" {
				($results).Count | Should -Be 5
			}
			$result = Get-AcmeAdminSp -SqlInstance $psitem -Database dbadb -Name restores
			It "restore sproc should auto start" {
				$results.AutoStart | Should -BeTrue
			}
		}
	}
}

To ensure that the tests that you write will display correctly on the PowerBi report and follow our coding guidelines please run the unit test prior to submitting a PR. You ca do this from the root of the module by running

Invoke-Pester .\Tests\Unit.Tests.ps1

Once you reimport the module Import-Module dbachecks -Force, you should see the checks appear in Get-DbcCheck. DbcCheck shows an index of all checks.

Before image

After image

If you have any questions, please ask us in #dbachecks on the SQL Community Slack.

Clone this wiki locally