Skip to content

Commit d362529

Browse files
committed
Fix tests
1 parent f6b70ac commit d362529

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

source/Private/Invoke-ReportServerSetupAction.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ function Invoke-ReportServerSetupAction
154154
[Parameter(ParameterSetName = 'Install')]
155155
[Parameter(ParameterSetName = 'Repair')]
156156
[ValidateScript({
157-
if (-not (Test-Path -Path (Split-Path -Path $_ -Parent) -PathType 'Container'))
157+
$parentInstallFolder = Split-Path -Path $_ -Parent
158+
159+
if (-not (Test-Path -Path $parentInstallFolder))
158160
{
159161
throw $script:localizedData.ReportServerSetupAction_InstallFolderNotFound
160162
}

source/en-US/SqlServerDsc.strings.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ ConvertFrom-StringData @'
9898
ReportServerSetupAction_ReportServerExecutableNotFound = The specified executable does not exist.
9999
ReportServerSetupAction_InstallFolderNotFound = The parent of the specified install folder does not exist.
100100
ReportServerSetupAction_SetupArguments = Specified executable arguments: {0}
101-
ReportServerSetupAction_TimeoutExceeded = The setup action has exceeded the specified timeout of {0} seconds.
102101
ReportServerSetupAction_ShouldProcessVerboseDescription = Invoking the setup action '{0}'.
103102
ReportServerSetupAction_ShouldProcessVerboseWarning = Are you sure you want to invoke the setup action '{0}'?
104103
# This string shall not end with full stop (.) since it is used as a title of ShouldProcess messages.

tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,56 @@ Describe 'Invoke-ReportServerSetupAction' -Tag 'Private' {
9999
}
100100
}
101101

102+
Context 'When passing no existent path to parameter MediaPath' {
103+
BeforeAll {
104+
Mock -CommandName Assert-ElevatedUser
105+
106+
InModuleScope -ScriptBlock {
107+
$script:mockDefaultParameters = @{
108+
Install = $true
109+
AcceptLicensingTerms = $true
110+
# Invalid path to test error handling
111+
MediaPath = $TestDrive
112+
Force = $true
113+
}
114+
}
115+
}
116+
117+
It 'Should throw an error when the MediaPath does not exist' {
118+
InModuleScope -ScriptBlock {
119+
{ Invoke-ReportServerSetupAction @mockDefaultParameters } |
120+
Should -Throw -ExpectedMessage "Cannot validate argument on parameter 'MediaPath'. The specified executable does not exist."
121+
}
122+
}
123+
}
124+
125+
Context 'When passing no existent path to parameter InstallFolder' {
126+
BeforeAll {
127+
Mock -CommandName Assert-ElevatedUser
128+
129+
# Create the file "$TestDrive/ssrs.exe"
130+
New-Item -Path "$TestDrive/ssrs.exe" -ItemType File -Force | Out-Null
131+
132+
InModuleScope -ScriptBlock {
133+
$script:mockDefaultParameters = @{
134+
Install = $true
135+
AcceptLicensingTerms = $true
136+
MediaPath = "$TestDrive/ssrs.exe"
137+
# Invalid path to test error handling
138+
InstallFolder = "$TestDrive/MissingFolder2/SSRS"
139+
Force = $true
140+
}
141+
}
142+
}
143+
144+
It 'Should throw an error when the InstallFolder does not exist' {
145+
InModuleScope -ScriptBlock {
146+
{ Invoke-ReportServerSetupAction @mockDefaultParameters } |
147+
Should -Throw -ExpectedMessage "Cannot validate argument on parameter 'InstallFolder'. The parent of the specified install folder does not exist."
148+
}
149+
}
150+
}
151+
102152
Context 'When setup action is ''Install''' {
103153
BeforeAll {
104154
Mock -CommandName Assert-ElevatedUser

tests/Unit/Private/Invoke-SetupAction.Tests.ps1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,51 @@ Describe 'Invoke-SetupAction' -Tag 'Private' {
151151
}
152152
}
153153

154+
Context 'When passing no existent path to parameter MediaPath' {
155+
BeforeAll {
156+
Mock -CommandName Assert-ElevatedUser
157+
158+
InModuleScope -ScriptBlock {
159+
$script:mockDefaultParameters = @{
160+
Install = $true
161+
AcceptLicensingTerms = $true
162+
MediaPath = $TestDrive # Updated to an invalid path to test error handling
163+
Force = $true
164+
}
165+
}
166+
}
167+
168+
It 'Should throw an error when the MediaPath does not exist' {
169+
InModuleScope -ScriptBlock {
170+
{ Invoke-SetupAction @mockDefaultParameters } |
171+
Should -Throw -ExpectedMessage "Cannot validate argument on parameter 'MediaPath'. The specified media path does not exist or does not contain 'setup.exe'."
172+
}
173+
}
174+
}
175+
176+
Context 'When passing no existent path to parameter ConfigurationFile' {
177+
BeforeAll {
178+
Mock -CommandName Assert-ElevatedUser
179+
180+
InModuleScope -ScriptBlock {
181+
$script:mockDefaultParameters = @{
182+
Install = $true
183+
AcceptLicensingTerms = $true
184+
# Invalid path to test error handling
185+
ConfigurationFile = "$TestDrive/config.ini"
186+
Force = $true
187+
}
188+
}
189+
}
190+
191+
It 'Should throw an error when the MediaPath does not exist' {
192+
InModuleScope -ScriptBlock {
193+
{ Invoke-SetupAction @mockDefaultParameters } |
194+
Should -Throw -ExpectedMessage "Cannot validate argument on parameter 'ConfigurationFile'. The specified configuration file was not found."
195+
}
196+
}
197+
}
198+
154199
Context 'When setup action is ''Install''' {
155200
BeforeAll {
156201
Mock -CommandName Assert-SetupActionProperties

0 commit comments

Comments
 (0)