Skip to content

Commit

Permalink
fix reply error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
akuzia committed Oct 19, 2022
1 parent f85817a commit cfd7f76
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
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('127.0.0.1', ['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(
'dial tcp 127.0.0.1:22: connect: connection refused',
$report->getErrorOutput()
);
}

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

0 comments on commit cfd7f76

Please sign in to comment.