@@ -428,6 +428,134 @@ Describe 'Invoke-ReportServerSetupAction' -Tag 'Private' {
428428 }
429429 }
430430 }
431+
432+ Context ' When path parameters contain environment variables' {
433+ BeforeAll {
434+ # Mock Test-Path to return $true for all paths in this context
435+ Mock - CommandName Test-Path - MockWith {
436+ return $true
437+ }
438+
439+ Mock - CommandName Start-SqlSetupProcess - MockWith {
440+ return 0
441+ } - RemoveParameterValidation ' FilePath'
442+
443+ Mock - CommandName Format-Path - MockWith {
444+ # Return expanded path for testing
445+ return ' C:\Logs\Test\setup.log'
446+ } - ParameterFilter {
447+ $Path -eq ' %TEMP%\setup.log'
448+ }
449+
450+ Mock - CommandName Format-Path - MockWith {
451+ return ' C:\Program Files\ReportServer'
452+ } - ParameterFilter {
453+ $Path -eq ' %ProgramFiles%\ReportServer'
454+ }
455+
456+ Mock - CommandName Format-Path - MockWith {
457+ return ' C:\SqlMedia\setup.exe'
458+ } - ParameterFilter {
459+ $Path -eq ' %SystemDrive%\SqlMedia\setup.exe'
460+ }
461+
462+ InModuleScope - ScriptBlock {
463+ $script :mockDefaultParameters = @ {
464+ Install = $true
465+ AcceptLicensingTerms = $true
466+ MediaPath = ' %SystemDrive%\SqlMedia\setup.exe'
467+ Force = $true
468+ }
469+ }
470+ }
471+
472+ It ' Should call Format-Path for MediaPath parameter' {
473+ InModuleScope - ScriptBlock {
474+ Invoke-ReportServerSetupAction @mockDefaultParameters
475+
476+ Should - Invoke - CommandName Format-Path - ParameterFilter {
477+ $Path -eq ' %SystemDrive%\SqlMedia\setup.exe' -and
478+ $EnsureDriveLetterRoot -eq $true -and
479+ $NoTrailingDirectorySeparator -eq $true -and
480+ $ExpandEnvironmentVariable -eq $true
481+ } - Exactly - Times 1 - Scope It
482+ }
483+ }
484+
485+ It ' Should call Format-Path for LogPath parameter when specified' {
486+ InModuleScope - ScriptBlock {
487+ $installParameters = $mockDefaultParameters.Clone ()
488+ $installParameters.LogPath = ' %TEMP%\setup.log'
489+
490+ Invoke-ReportServerSetupAction @installParameters
491+
492+ Should - Invoke - CommandName Format-Path - ParameterFilter {
493+ $Path -eq ' %TEMP%\setup.log' -and
494+ $EnsureDriveLetterRoot -eq $true -and
495+ $NoTrailingDirectorySeparator -eq $true -and
496+ $ExpandEnvironmentVariable -eq $true
497+ } - Exactly - Times 1 - Scope It
498+ }
499+ }
500+
501+ It ' Should call Format-Path for InstallFolder parameter when specified' {
502+ InModuleScope - ScriptBlock {
503+ $installParameters = $mockDefaultParameters.Clone ()
504+ $installParameters.InstallFolder = ' %ProgramFiles%\ReportServer'
505+
506+ Invoke-ReportServerSetupAction @installParameters
507+
508+ Should - Invoke - CommandName Format-Path - ParameterFilter {
509+ $Path -eq ' %ProgramFiles%\ReportServer' -and
510+ $EnsureDriveLetterRoot -eq $true -and
511+ $NoTrailingDirectorySeparator -eq $true -and
512+ $ExpandEnvironmentVariable -eq $true
513+ } - Exactly - Times 1 - Scope It
514+ }
515+ }
516+
517+ It ' Should pass the expanded path to Start-SqlSetupProcess for MediaPath' {
518+ InModuleScope - ScriptBlock {
519+ Invoke-ReportServerSetupAction @mockDefaultParameters
520+
521+ Should - Invoke - CommandName Start-SqlSetupProcess - ParameterFilter {
522+ $FilePath -eq ' C:\SqlMedia\setup.exe'
523+ } - Exactly - Times 1 - Scope It
524+ }
525+ }
526+
527+ It ' Should pass the expanded path in ArgumentList for LogPath' {
528+ InModuleScope - ScriptBlock {
529+ $installParameters = $mockDefaultParameters.Clone ()
530+ $installParameters.LogPath = ' %TEMP%\setup.log'
531+
532+ Invoke-ReportServerSetupAction @installParameters
533+
534+ Should - Invoke - CommandName Start-SqlSetupProcess - ParameterFilter {
535+ $ArgumentList | Should - MatchExactly ' \/log "C:\\Logs\\Test\\setup\.log"'
536+
537+ # Return $true if none of the above throw.
538+ $true
539+ } - Exactly - Times 1 - Scope It
540+ }
541+ }
542+
543+ It ' Should pass the expanded path in ArgumentList for InstallFolder' {
544+ InModuleScope - ScriptBlock {
545+ $installParameters = $mockDefaultParameters.Clone ()
546+ $installParameters.InstallFolder = ' %ProgramFiles%\ReportServer'
547+
548+ Invoke-ReportServerSetupAction @installParameters
549+
550+ Should - Invoke - CommandName Start-SqlSetupProcess - ParameterFilter {
551+ $ArgumentList | Should - MatchExactly ' \/InstallFolder="C:\\Program Files\\ReportServer"'
552+
553+ # Return $true if none of the above throw.
554+ $true
555+ } - Exactly - Times 1 - Scope It
556+ }
557+ }
558+ }
431559 }
432560
433561 Context ' When setup action is '' Uninstall'' ' {
0 commit comments