Skip to content

Commit 4a7c9ce

Browse files
committed
Added integration tests based on code review feedback
1 parent 8ac2d43 commit 4a7c9ce

3 files changed

Lines changed: 288 additions & 1 deletion

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Configuration xScheduledTask_Add
2+
{
3+
Import-DscResource -ModuleName xComputerManagement
4+
node "localhost" {
5+
xScheduledTask xScheduledTask_Add {
6+
TaskName = "Test task"
7+
TaskPath = "\xComputerManagement\"
8+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
9+
ScheduleType = "Minutes"
10+
RepeatInterval = 15
11+
}
12+
}
13+
}
14+
15+
Configuration xScheduledTask_Edit1
16+
{
17+
Import-DscResource -ModuleName xComputerManagement
18+
node "localhost" {
19+
xScheduledTask xScheduledTask_Edit1 {
20+
TaskName = "Test task"
21+
TaskPath = "\xComputerManagement\"
22+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
23+
ScheduleType = "Minutes"
24+
RepeatInterval = 45
25+
}
26+
}
27+
}
28+
29+
Configuration xScheduledTask_Edit2
30+
{
31+
Import-DscResource -ModuleName xComputerManagement
32+
node "localhost" {
33+
xScheduledTask xScheduledTask_Edit2 {
34+
TaskName = "Test task"
35+
TaskPath = "\xComputerManagement\"
36+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
37+
ScheduleType = "Hourly"
38+
RepeatInterval = 4
39+
}
40+
}
41+
}
42+
43+
Configuration xScheduledTask_Edit3
44+
{
45+
Import-DscResource -ModuleName xComputerManagement
46+
node "localhost" {
47+
xScheduledTask xScheduledTask_Edit3 {
48+
TaskName = "Test task"
49+
TaskPath = "\xComputerManagement\"
50+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
51+
ScheduleType = "Daily"
52+
RepeatInterval = 1
53+
}
54+
}
55+
}
56+
57+
Configuration xScheduledTask_Edit4
58+
{
59+
Import-DscResource -ModuleName xComputerManagement
60+
node "localhost" {
61+
xScheduledTask xScheduledTask_Edit3 {
62+
TaskName = "Test task"
63+
TaskPath = "\xComputerManagement\"
64+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
65+
ActionWorkingPath = "C:\"
66+
ScheduleType = "Daily"
67+
RepeatInterval = 1
68+
}
69+
}
70+
}
71+
72+
Configuration xScheduledTask_Edit5
73+
{
74+
Import-DscResource -ModuleName xComputerManagement
75+
node "localhost" {
76+
xScheduledTask xScheduledTask_Edit5 {
77+
TaskName = "Test task"
78+
TaskPath = "\xComputerManagement\"
79+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
80+
ActionWorkingPath = "C:\"
81+
ActionArguments = "-Command 'Get-ChildItem'"
82+
ScheduleType = "Daily"
83+
RepeatInterval = 1
84+
}
85+
}
86+
}
87+
88+
Configuration xScheduledTask_Remove
89+
{
90+
Import-DscResource -ModuleName xComputerManagement
91+
node "localhost" {
92+
xScheduledTask xScheduledTask_Remove {
93+
TaskName = "Test task"
94+
TaskPath = "\xComputerManagement\"
95+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
96+
ScheduleType = "Minutes"
97+
RepeatInterval = 15
98+
Ensure="Absent"
99+
}
100+
}
101+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
$Global:DSCModuleName = 'xComputerManagement'
2+
$Global:DSCResourceName = 'MSFT_xScheduledTask'
3+
4+
#region HEADER
5+
# Unit Test Template Version: 1.1.0
6+
[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))
7+
if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
8+
(-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
9+
{
10+
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'))
11+
}
12+
13+
Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
14+
$TestEnvironment = Initialize-TestEnvironment `
15+
-DSCModuleName $Global:DSCModuleName `
16+
-DSCResourceName $Global:DSCResourceName `
17+
-TestType Integration
18+
19+
# Begin Testing
20+
try
21+
{
22+
#region Pester Tests
23+
Describe $Global:DSCResourceName {
24+
25+
Context "No scheduled task exists, but it should" {
26+
CurrentConfig = "xScheduledTask_Add"
27+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
28+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
29+
30+
It "should compile a MOF file without error" {
31+
{
32+
. $CurrentConfig -OutputPath $ConfigDir
33+
} | Should Not Throw
34+
}
35+
36+
It "should apply the MOF correctly" {
37+
{
38+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
39+
} | Should Not Throw
40+
}
41+
42+
It "should return a compliant state after being applied" {
43+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
44+
}
45+
}
46+
47+
Context "A scheduled task with minutes based repetition exists, but has the wrong settings" {
48+
CurrentConfig = "xScheduledTask_Edit1"
49+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
50+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
51+
52+
It "should compile a MOF file without error" {
53+
{
54+
. $CurrentConfig -OutputPath $ConfigDir
55+
} | Should Not Throw
56+
}
57+
58+
It "should apply the MOF correctly" {
59+
{
60+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
61+
} | Should Not Throw
62+
}
63+
64+
It "should return a compliant state after being applied" {
65+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
66+
}
67+
}
68+
69+
Context "A scheduled task with hourly based repetition exists, but has the wrong settings" {
70+
CurrentConfig = "xScheduledTask_Edit2"
71+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
72+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
73+
74+
It "should compile a MOF file without error" {
75+
{
76+
. $CurrentConfig -OutputPath $ConfigDir
77+
} | Should Not Throw
78+
}
79+
80+
It "should apply the MOF correctly" {
81+
{
82+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
83+
} | Should Not Throw
84+
}
85+
86+
It "should return a compliant state after being applied" {
87+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
88+
}
89+
}
90+
91+
Context "A scheduled task with daily based repetition exists, but has the wrong settings" {
92+
CurrentConfig = "xScheduledTask_Edit3"
93+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
94+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
95+
96+
It "should compile a MOF file without error" {
97+
{
98+
. $CurrentConfig -OutputPath $ConfigDir
99+
} | Should Not Throw
100+
}
101+
102+
It "should apply the MOF correctly" {
103+
{
104+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
105+
} | Should Not Throw
106+
}
107+
108+
It "should return a compliant state after being applied" {
109+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
110+
}
111+
}
112+
113+
Context "A scheduled task exists and is configured with the wrong working directory" {
114+
CurrentConfig = "xScheduledTask_Edit4"
115+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
116+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
117+
118+
It "should compile a MOF file without error" {
119+
{
120+
. $CurrentConfig -OutputPath $ConfigDir
121+
} | Should Not Throw
122+
}
123+
124+
It "should apply the MOF correctly" {
125+
{
126+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
127+
} | Should Not Throw
128+
}
129+
130+
It "should return a compliant state after being applied" {
131+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
132+
}
133+
}
134+
135+
Context "A scheduled task exists and is configured with the wrong executable arguments" {
136+
CurrentConfig = "xScheduledTask_Edit5"
137+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
138+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
139+
140+
It "should compile a MOF file without error" {
141+
{
142+
. $CurrentConfig -OutputPath $ConfigDir
143+
} | Should Not Throw
144+
}
145+
146+
It "should apply the MOF correctly" {
147+
{
148+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
149+
} | Should Not Throw
150+
}
151+
152+
It "should return a compliant state after being applied" {
153+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
154+
}
155+
}
156+
157+
Context "A scheduled task exists, but it shouldn't" {
158+
CurrentConfig = "xScheduledTask_Remove"
159+
$ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig)
160+
$ConfigMof = (Join-Path $ConfigDir "localhost.mof")
161+
162+
It "should compile a MOF file without error" {
163+
{
164+
. $CurrentConfig -OutputPath $ConfigDir
165+
} | Should Not Throw
166+
}
167+
168+
It "should apply the MOF correctly" {
169+
{
170+
Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force
171+
} | Should Not Throw
172+
}
173+
174+
It "should return a compliant state after being applied" {
175+
(Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true
176+
}
177+
}
178+
}
179+
#endregion
180+
}
181+
finally
182+
{
183+
#region FOOTER
184+
Restore-TestEnvironment -TestEnvironment $TestEnvironment
185+
#endregion
186+
}

Tests/Unit/MSFT_xScheduledTask.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$Global:DSCModuleName = 'xScheduledTask'
1+
$Global:DSCModuleName = 'xComputerManagement'
22
$Global:DSCResourceName = 'MSFT_xScheduledTask'
33

44
#region HEADER

0 commit comments

Comments
 (0)