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