Skip to content

Commit

Permalink
linux fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaneri committed Nov 26, 2024
1 parent 7f77d94 commit 035cb12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/Private/Service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = @{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions tests/unit/Service.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand All @@ -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
Expand Down Expand Up @@ -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 }

Expand All @@ -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
Expand Down

0 comments on commit 035cb12

Please sign in to comment.