diff --git a/src/Private/Service.ps1 b/src/Private/Service.ps1 index 9a73bfa80..6524a6c7f 100644 --- a/src/Private/Service.ps1 +++ b/src/Private/Service.ps1 @@ -244,7 +244,7 @@ function Register-PodeMacService { $Agent ) - $nameService = Get-PodeRealServiceName + $nameService = Get-PodeRealServiceName -Name $Name # Check if the service is already registered if ((Test-PodeMacOsServiceIsRegistered $nameService)) { @@ -410,7 +410,7 @@ function Register-PodeLinuxService { [string] $OsArchitecture ) - $nameService = Get-PodeRealServiceName + $nameService = Get-PodeRealServiceName -Name $Name $null = systemctl status $nameService 2>&1 # Check if the service is already registered @@ -1166,7 +1166,7 @@ function Send-PodeServiceSignal { ) # Standardize service naming for Linux/macOS - $nameService = Get-PodeRealServiceName + $nameService = Get-PodeRealServiceName -Name $Name # Map signal names to their corresponding Unix signal numbers $signalMap = @{ @@ -1372,7 +1372,7 @@ function Get-PodeServiceStatus { elseif ($IsLinux) { try { - $nameService = Get-PodeRealServiceName + $nameService = Get-PodeRealServiceName -Name $Name # Check if the service exists on Linux (systemd) if ((Test-PodeLinuxServiceIsRegistered -Name $nameService)) { $servicePid = 0 @@ -1432,7 +1432,7 @@ function Get-PodeServiceStatus { elseif ($IsMacOS) { try { - $nameService = Get-PodeRealServiceName + $nameService = Get-PodeRealServiceName -Name $Name # Check if the service exists on macOS (launchctl) if ((Test-PodeMacOsServiceIsRegistered $nameService )) { $servicePid = Get-PodeMacOsServicePid -Name $nameService # Extract the PID from the match diff --git a/tests/unit/Service.Tests.ps1 b/tests/unit/Service.Tests.ps1 index b5d03f700..92b7ba307 100644 --- a/tests/unit/Service.Tests.ps1 +++ b/tests/unit/Service.Tests.ps1 @@ -114,7 +114,7 @@ Describe 'Start-PodeService' { Mock -CommandName Start-PodeMacOsService Mock -CommandName Write-PodeErrorLog Mock -CommandName Write-Error - Mock -CommandName Get-PodeServiceStatus {return @{Status=''}} + Mock -CommandName Get-PodeServiceStatus { return @{Status = '' } } } Context 'On Windows platform' { @@ -130,7 +130,8 @@ Describe 'Start-PodeService' { } [pscustomobject]@{ Name = 'TestService'; Status = $status } } - Mock -CommandName Invoke-PodeWinElevatedCommand -MockWith { return $true } + Mock -CommandName Wait-PodeServiceStatus { $true } + Mock -CommandName Invoke-PodeWinElevatedCommand -MockWith { $true } # Act Start-PodeService -Name 'TestService' | Should -Be $true @@ -161,17 +162,17 @@ Describe 'Start-PodeService' { Context 'On Linux platform' { It 'Starts a stopped service successfully' -Skip:(!$IsLinux) { - $script:status = $null - Mock -CommandName Test-PodeLinuxServiceIsActive -MockWith { - if ($null -eq $script:status ) { - $script:status = $false + $script:status = 'none' + Mock -CommandName Get-PodeServiceStatus -MockWith { + if ($script:status -eq 'none') { + $script:status = 'Stopped' } else { - $script:status = $true + $script:status = 'Running' } - return $script:status + [pscustomobject]@{ Name = 'TestService'; Status = $status } } - + Mock -CommandName Wait-PodeServiceStatus { $true } Mock -CommandName Test-PodeLinuxServiceIsRegistered -MockWith { $true } Mock -CommandName Start-PodeLinuxService -MockWith { $true } @@ -183,10 +184,12 @@ Describe 'Start-PodeService' { } It 'Starts a started service ' -Skip:(!$IsLinux) { - - Mock -CommandName Test-PodeLinuxServiceIsActive -MockWith { $true } - Mock -CommandName Test-PodeLinuxServiceIsRegistered -MockWith { $true } + Mock -CommandName Start-PodeLinuxService -MockWith { $true } + Mock -CommandName Get-PodeServiceStatus -MockWith { + [pscustomobject]@{ Name = 'TestService'; Status = 'Running' } + } + # Act Start-PodeService -Name 'TestService' | Should -Be $true