Skip to content
Rob Sewell edited this page Feb 20, 2018 · 19 revisions

This wiki is currently dedicated to dbachecks development. Please read the FAQ page and the readme page for usage information

Solid example

Below you will find a great example of our development standards

Describe "Linked Server Connection" -Tags LinkedServerConnection, Connectivity, $filename {
	(Get-SqlInstance).ForEach{
		Context "Testing Linked Servers on $psitem" {
			(Test-DbaLinkedServerConnection -SqlInstance $psitem).ForEach{
				It "Linked Server $($psitem.LinkedServerName) has connectivity" {
					$psitem.Connectivity | Should -BeTrue
				}
			}
		}
	}
}
  • The parameter -Tags is pluralized
  • The whole line uses double quotes, which helps with our parsing for Get-DbcCheck
  • Actual tags are singular
  • The first Tag is unique, thereby "naming" the test LinkedServerConnection
  • The unique tag shows up as a unique tag in Get-DbcCheck
  • Context mentions the instance or computer name ($psitem)

image

  • The internal command Get-SqlInstance or Get-ComputerName is used
  • The ForEach method is used (PS4+)
  • $psitem is used in lieu of $_
  • The assertion should validate to a value instead of True or False if possible - so

'The Results' | Should -Be 'The Results'

rather than

'The Results' -eq 'The Results' | Should -BeTrue

Context usage

Every Describe should have at least one Context that mentions the $psitem. The $psitem on the Context block should be always at the end of the statement. At the PowerBI transformation we split and get the last position as the Instance value.

Configuration System

This module relies on PSFramework for its infrastructure including the config system. The config system is mostly for end-user preferences, such as setting a static list of servers or skipping (internal) tests.

Users can skip entire tests by specifying the -ExcludeTag. Each test is automatically tagged with its file name (backups.Tests.ps1 -> backups).

Check out configuration.ps1

image

Each configuration must be "initialized" in this file and then any changes are persisted once the user executes Set-DbaConfig

Tags

Pester tags, like PowerShell command names and parameter names, are singular. Each command can have multiple tags such as Database, Restore and then the filename will also be attached as well.

Unit Tests

We have created unit tests for ensuring that these standards are followed. If you would like to see how this is done, please read the blog post

You can run the Unit Test before submitting a PR using

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

Filenames

Checks are located in the checks folder. Please ask if you need to add a new file, which is essentially a new Group or Category.

Auto completion (TEPP)

Auto-complete is provided by PSFramework. You can edit autocomplete.ps1 as required.

image