Skip to content

Commit 4653447

Browse files
author
Andreas Frömer
committed
Fix issue with failed service
Failed services may contain non valid character in front of there service name. This commit improves the regex to extract the service name.
1 parent 988931d commit 4653447

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/Utils/OutputFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class OutputFetcher
1919
*/
2020
public static function fetchUnitNames(string $suffix, string $output): array
2121
{
22-
preg_match_all('/^\s*(?<unit>.*)\.' . $suffix . '\s.*$/m', $output, $matches);
22+
preg_match_all('/^[^[:alnum:]-_\.@]*(?<unit>.*)\.' . $suffix . '\s.*$/m', $output, $matches);
2323
return $matches['unit'] ?? [];
2424
}
2525
}

tests/Integration/SystemCtlTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function testListUnitsWithAvailableUnits()
4545
beanstalkd.service loaded active running
4646
console-setup.service loaded active exited
4747
cron.service loaded active running
48+
[email protected] loaded failed failed
4849
EOT;
4950

5051
$command = $this->prophesize(CommandInterface::class);
@@ -57,7 +58,7 @@ public function testListUnitsWithAvailableUnits()
5758
$systemctl->setCommandDispatcher($dispatcherStub->reveal());
5859

5960
$units = $systemctl->listUnits(null, SystemCtl::AVAILABLE_UNITS);
60-
$this->assertCount(11, $units);
61+
$this->assertCount(12, $units);
6162
}
6263

6364
public function testListUnitsWithSupportedUnits()

tests/Unit/Utils/OutputFetcherTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@ public function itDeterminesTheCorrectAmountOfUnits(
3535
public function itDeterminesTheCorrectAmountOfUnitsDataProvider(): array
3636
{
3737
$output = <<<OUTPUT
38-
superservice.service Active running
39-
awesomeservice.service Active running
40-
nonservice.timer Active running
41-
superservice.mount Active running
42-
awesomeservice.mount Active running
43-
nonservice.timer Active running
44-
superservice.service Active running
45-
awesomeservice.service Active running
38+
superservice.service active running
39+
awesomeservice.service active running
40+
nonservice.timer active running
41+
superservice.mount active running
42+
awesomeservice.mount active running
43+
nonservice.timer active running
44+
superservice.service active running
45+
awesomeservice.service active running
46+
[email protected] loaded failed failed
4647
OUTPUT;
4748

4849
return [
4950
[
5051
'output' => $output,
5152
'suffix' => 'service',
52-
'amount' => 4,
53+
'amount' => 5,
5354
],
5455
[
5556
'output' => $output,
@@ -97,6 +98,7 @@ public function itOnlyExtractsTheUnitNamesDataProvider(): array
9798
nonservice.timer Active running
9899
[email protected] Active running
99100
[email protected] Active running
101+
[email protected] loaded failed failed
100102
OUTPUT;
101103

102104
return [
@@ -108,6 +110,7 @@ public function itOnlyExtractsTheUnitNamesDataProvider(): array
108110
'foo-bar',
109111
'instance-service@1',
110112
'instance-service@foo',
113+
'failed-service@foo'
111114
],
112115
],
113116
[

0 commit comments

Comments
 (0)