-
-
Notifications
You must be signed in to change notification settings - Fork 831
/
Copy pathCopy-DbaSpConfigure.Tests.ps1
79 lines (69 loc) · 3.36 KB
/
Copy-DbaSpConfigure.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)
Describe "Copy-DbaSpConfigure" -Tag "UnitTests" {
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaSpConfigure
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"ConfigName",
"ExcludeConfigName",
"EnableException",
"Confirm",
"WhatIf"
)
}
It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}
It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasParams = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasParams | Should -BeNullOrEmpty
}
}
}
Describe "Copy-DbaSpConfigure" -Tag "IntegrationTests" {
Context "When copying configuration with the same properties" {
BeforeAll {
$sourceConfig = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout
$destConfig = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout
$sourceConfigValue = $sourceConfig.ConfiguredValue
$destConfigValue = $destConfig.ConfiguredValue
# Set different values to ensure they don't match
if ($sourceConfigValue -and $destConfigValue) {
$newValue = $sourceConfigValue + $destConfigValue
$null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout -Value $newValue
}
}
AfterAll {
if ($destConfigValue -and $destConfigValue -ne $sourceConfigValue) {
$null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout -Value $destConfigValue
}
}
It "Should start with different values" {
$config1 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout
$config2 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout
$config1.ConfiguredValue | Should -Not -Be $config2.ConfiguredValue
}
It "Should copy successfully" {
$results = Copy-DbaSpConfigure -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -ConfigName RemoteQueryTimeout
$results.Status | Should -Be "Successful"
}
It "Should retain the same properties after copy" {
$config1 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout
$config2 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout
$config1.ConfiguredValue | Should -Be $config2.ConfiguredValue
}
It "Should not modify the source configuration" {
$newConfig = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout
$newConfig.ConfiguredValue | Should -Be $sourceConfigValue
}
}
}