forked from dataplat/dbatools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-DbaAgentJob.Tests.ps1
More file actions
65 lines (62 loc) · 3.14 KB
/
Copy pathGet-DbaAgentJob.Tests.ps1
File metadata and controls
65 lines (62 loc) · 3.14 KB
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
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 6
$defaultParamCount = 11
[object[]]$params = (Get-ChildItem function:\Get-DbaAgentJob).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'ExcludeJob', 'NoDisabledJobs', 'EnableException'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
}
}
}
Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "Command gets jobs" {
BeforeAll {
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled
}
AfterAll {
$null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled
}
$results = Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object {$_.Name -match "dbatoolsci"}
It "Should get 2 dbatoolsci jobs" {
$results.count | Should Be 2
}
$results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob
It "Should get a specific job" {
$results.name | Should Be "dbatoolsci_testjob"
}
}
Context "Command gets no disabled jobs" {
BeforeAll {
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled
}
AfterAll {
$null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled
}
$results = Get-DbaAgentJob -SqlInstance $script:instance2 -NoDisabledJobs | Where-Object {$_.Name -match "dbatoolsci"}
It "Should return only enabled jobs" {
$results.enabled -contains $False | Should Be $False
}
}
Context "Command doesn't get excluded job" {
BeforeAll {
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled
}
AfterAll {
$null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled
}
$results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeJob dbatoolsci_testjob | Where-Object {$_.Name -match "dbatoolsci"}
It "Should not return excluded job" {
$results.name -contains "dbatoolsci_testjob" | Should Be $False
}
}
}