-
-
Notifications
You must be signed in to change notification settings - Fork 830
/
Copy pathCopy-DbaAgentJob.Tests.ps1
81 lines (72 loc) · 3.17 KB
/
Copy-DbaAgentJob.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
80
81
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)
Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" {
BeforeAll {
$null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob
$null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled
$sourcejobs = Get-DbaAgentJob -SqlInstance $TestConfig.instance2
$destjobs = Get-DbaAgentJob -SqlInstance $TestConfig.instance3
}
AfterAll {
$null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false
$null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false
}
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaAgentJob
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"Job",
"ExcludeJob",
"DisableOnSource",
"DisableOnDestination",
"Force",
"InputObject",
"EnableException",
"Confirm",
"WhatIf"
)
}
It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}
It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
Context "Command copies jobs properly" {
BeforeAll {
$results = Copy-DbaAgentJob -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Job dbatoolsci_copyjob
}
It "returns one success" {
$results.Name | Should -Be "dbatoolsci_copyjob"
$results.Status | Should -Be "Successful"
}
It "did not copy dbatoolsci_copyjob_disabled" {
Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled | Should -BeNullOrEmpty
}
It "disables jobs when requested" {
$splatCopyJob = @{
Source = $TestConfig.instance2
Destination = $TestConfig.instance3
Job = "dbatoolsci_copyjob_disabled"
DisableOnSource = $true
DisableOnDestination = $true
Force = $true
}
$results = Copy-DbaAgentJob @splatCopyJob
$results.Name | Should -Be "dbatoolsci_copyjob_disabled"
$results.Status | Should -Be "Successful"
(Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled).Enabled | Should -BeFalse
(Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled).Enabled | Should -BeFalse
}
}
}