forked from dataplat/dbatools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-DbaRegServerGroup.Tests.ps1
55 lines (52 loc) · 2.98 KB
/
Add-DbaRegServerGroup.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'Description', 'Group', 'InputObject', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
Context "Setup" {
BeforeAll {
$group = "dbatoolsci-group1"
$group2 = "dbatoolsci-group2"
$description = "group description"
$descriptionUpdated = "group description updated"
}
AfterAll {
Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false
}
It "adds a registered server group" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group
$results.Name | Should -Be $group
$results.SqlInstance | Should -Not -Be $null
}
It "adds a registered server group with extended properties" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 -Description $description
$results.Name | Should -Be $group2
$results.Description | Should -Be $description
$results.SqlInstance | Should -Not -Be $null
}
It "supports hella pipe" {
$results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous
$results.Group | Should -Be 'dbatoolsci-first\dbatoolsci-second\dbatoolsci-third'
}
It "adds a registered server group and sub-group when not exists" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $description
$results.Name | Should -Be $group2
$results.SqlInstance | Should -Not -Be $null
}
It "updates description of sub-group when it already exists" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $descriptionUpdated
$results.Name | Should -Be $group2
$results.Description | Should -Be $descriptionUpdated
$results.SqlInstance | Should -Not -Be $null
}
}
}