Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Dplr/TaskReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getType(): string

public function getOutput(): ?string
{
if (!isset($this->data['Stdout'])) {
if (!isset($this->data['Stdout']) && '' !== $this->data['StdOut']) {
return null;
}

Expand All @@ -91,12 +91,12 @@ public function getOutput(): ?string

public function getErrorOutput(): ?string
{
if (isset($this->data['Stderr'])) {
if (isset($this->data['Stderr']) && '' !== $this->data['Stderr']) {
return $this->data['Stderr'];
}

if (isset($this->data['ErrorMsg'])) {
return $this->data['ErrorMsg'];
if (isset($this->data['ErrMsg']) && '' !== $this->data['ErrMsg']) {
return $this->data['ErrMsg'];
}

return null;
Expand Down
65 changes: 65 additions & 0 deletions tests/Dplr/Tests/DplrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,71 @@ public function testLimitedConcurrency(): void
}
}

public function testShellErrorReporting(): void
{
$d = self::getDplr();
$d->upload(self::getFixturesPath() . '/files/1.txt', '/foo/1.txt', 'job');

$this->assertTrue($d->hasTasks());

$output = '';
$d->run(function (string $s) use (&$output) {
$output .= $s;
});

$this->assertFalse($d->isSuccessful());
$this->assertFalse($d->hasTasks());
$this->assertEquals(
'CPY ' . self::getFixturesPath() . "/files/1.txt -> /foo/1.txt E\n",
$output
);

$report = $d->getReport();
$this->assertEquals(1, $report['total']);
$this->assertEquals(0, $report['successful']);
$this->assertEquals(1, $report['failed']);

$report = $d->getReports()[0];
$this->assertEquals(
$report->getErrorOutput(),
"ash: can't create /foo/1.txt: nonexistent directory\n"
);
}

public function testGosshaErrorReporting(): void
{
$d = new Dplr(self::USER, self::GOSSHA_PATH, self::SSH_KEY);
$d
->addServer('remote_4', ['job', 'all'])
;
$d->upload(self::getFixturesPath() . '/files/1.txt', '/foo/1.txt', 'job');

$this->assertTrue($d->hasTasks());

$output = '';
$d->run(function (string $s) use (&$output) {
$output .= $s;
});

$this->assertFalse($d->isSuccessful());
$this->assertFalse($d->hasTasks());
$this->assertEquals(
'CPY ' . self::getFixturesPath() . "/files/1.txt -> /foo/1.txt E\n",
$output
);

$report = $d->getReport();
$this->assertEquals(1, $report['total']);
$this->assertEquals(0, $report['successful']);
$this->assertEquals(1, $report['failed']);

$report = $d->getReports()[0];
$this->assertEquals(
$report->getErrorOutput(),
'dial tcp: lookup remote_4: no such host'
);
}

private static function getFixturesPath(): string
{
return realpath(__DIR__ . '/../Fixtures');
Expand Down