-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat - Add support of Process concurrently and pool
- Loading branch information
Showing
4 changed files
with
144 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,23 @@ | |
use Bagel\ProcessSsh\PendingProcess; | ||
use Bagel\ProcessSsh\Providers\ProcessSshServiceProvider; | ||
use Illuminate\Process\FakeProcessResult; | ||
use Illuminate\Process\Pool; | ||
use Illuminate\Support\Facades\Process; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
uses(TestCase::class)->beforeEach(function () { | ||
$this->app->register(ProcessSshServiceProvider::class); | ||
|
||
$this->basicSshConfig = [ | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'port' => 22, | ||
]; | ||
}); | ||
|
||
it('process config set', function () { | ||
$process = Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'port' => 22, | ||
'extraOptions' => [ | ||
|
@@ -22,7 +29,7 @@ | |
'private_key' => '/path/to/key', | ||
]); | ||
|
||
expect($process->sshConfig()['host'])->toBe('example.com'); | ||
expect($process->sshConfig()['host'])->toBe('192.178.0.1'); | ||
expect($process->sshConfig()['user'])->toBe('ubuntu'); | ||
expect($process->sshConfig()['port'])->toBe(22); | ||
expect($process->sshConfig()['extraOptions'])->toBe([ | ||
|
@@ -34,7 +41,7 @@ | |
|
||
it('process add extra options', function () { | ||
$process = Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'port' => 22, | ||
])->addExtraOption('-o StrictHostKeyChecking=no'); | ||
|
@@ -46,7 +53,7 @@ | |
|
||
it('process disableStrictHostKeyChecking', function () { | ||
$process = Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'port' => 22, | ||
])->disableStrictHostKeyChecking(); | ||
|
@@ -87,12 +94,12 @@ | |
Process::fake(); | ||
|
||
$process = Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
]) | ||
->disableStrictHostKeyChecking() | ||
->run('ls -al'); | ||
|
||
expect($process->command())->toBe("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null example.com 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
expect($process->command())->toBe("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null 192.178.0.1 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
|
||
Process::assertRan('ls -al'); | ||
}); | ||
|
@@ -101,7 +108,7 @@ | |
Process::fake(); | ||
|
||
$process = Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'password' => 'password', | ||
'port' => 22, | ||
|
@@ -113,7 +120,7 @@ | |
->disableStrictHostKeyChecking() | ||
->run('ls -al'); | ||
|
||
expect($process->command())->toBe("sshpass -p 'password' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@example.com 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
expect($process->command())->toBe("sshpass -p 'password' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@192.178.0.1 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
|
||
Process::assertRan('ls -al'); | ||
}); | ||
|
@@ -122,37 +129,19 @@ | |
Process::fake(); | ||
|
||
$process = Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'port' => 22, | ||
'private_key' => '/path/to/key', | ||
]) | ||
->disableStrictHostKeyChecking() | ||
->run('ls -al'); | ||
|
||
expect($process->command())->toBe("ssh -i /path/to/key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@example.com 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
expect($process->command())->toBe("ssh -i /path/to/key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@192.178.0.1 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
|
||
Process::assertRan('ls -al'); | ||
}); | ||
|
||
it('exception thrown process run with array', function () { | ||
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => '127.0.0.1', | ||
])->run(['ls', '-al']); | ||
|
||
})->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections'); | ||
|
||
it('exception thrown process start with array', function () { | ||
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => '127.0.0.1', | ||
])->start(['ls', '-al']); | ||
|
||
})->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections'); | ||
|
||
it('Process can run normaly', function () { | ||
Process::fake(); | ||
|
||
|
@@ -183,7 +172,7 @@ | |
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'password' => 'password', | ||
'port' => 22, | ||
|
@@ -202,7 +191,7 @@ | |
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => 'example.com', | ||
'host' => '192.178.0.1', | ||
'user' => 'ubuntu', | ||
'password' => 'password', | ||
'port' => 22, | ||
|
@@ -217,60 +206,87 @@ | |
}); | ||
}); | ||
|
||
it('can\'t pool processes with SSH enabled', function () { | ||
it('invoke process::concurrently', function () { | ||
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => 'example.com', | ||
'user' => 'ubuntu', | ||
'password' => 'password', | ||
'port' => 22, | ||
])->pool(function () { | ||
// | ||
$process = Process::concurrently(function (Pool $pool) { | ||
$pool->command('ls -al'); | ||
$pool->command('whoami'); | ||
}); | ||
|
||
})->throws(InvalidArgumentException::class, 'Cannot pool processes with SSH enabled.'); | ||
expect($process[0]->command())->toBe('ls -al'); | ||
expect($process[1]->command())->toBe('whoami'); | ||
|
||
Process::assertRan('ls -al'); | ||
Process::assertRan('whoami'); | ||
}); | ||
|
||
it('can\'t pipe processes with SSH enabled', function () { | ||
it('invoke process::concurrently ssh', function () { | ||
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => 'example.com', | ||
'user' => 'ubuntu', | ||
'password' => 'password', | ||
'port' => 22, | ||
])->pipe(function () { | ||
// | ||
$process = Process::ssh($this->basicSshConfig)->concurrently(function (Pool $pool) { | ||
$pool->command('ls -al'); | ||
$pool->command('whoami'); | ||
}); | ||
|
||
})->throws(InvalidArgumentException::class, 'Cannot pipe processes with SSH enabled.'); | ||
expect($process[0]->command())->toBe("ssh [email protected] 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
expect($process[1]->command())->toBe("ssh [email protected] 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'whoami'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
|
||
}); | ||
|
||
it('can\'t concurrently processes with SSH enabled', function () { | ||
it('invoke process::pool', function () { | ||
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => 'example.com', | ||
'user' => 'ubuntu', | ||
'password' => 'password', | ||
'port' => 22, | ||
])->concurrently(function () { | ||
// | ||
$process = Process::pool(function (Pool $pool) { | ||
$pool->command('ls -al'); | ||
$pool->command('whoami'); | ||
}); | ||
|
||
$results = $process->wait(); | ||
expect($results[0]->command())->toBe('ls -al'); | ||
expect($results[1]->command())->toBe('whoami'); | ||
|
||
Process::assertRan('ls -al'); | ||
Process::assertRan('whoami'); | ||
}); | ||
|
||
it('invoke process::pool ssh', function () { | ||
Process::fake(); | ||
|
||
$process = Process::ssh($this->basicSshConfig)->pool(function (Pool $pool) { | ||
$pool->command('ls -al'); | ||
$pool->command('whoami'); | ||
}); | ||
|
||
})->throws(InvalidArgumentException::class, 'Cannot concurrently processes with SSH enabled.'); | ||
$results = $process->wait(); | ||
expect($results[0]->command())->toBe("ssh [email protected] 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'ls -al'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
expect($results[1]->command())->toBe("ssh [email protected] 'bash -se' << \EOF-PROCESS-SSH".PHP_EOL.'whoami'.PHP_EOL.'EOF-PROCESS-SSH'); | ||
|
||
}); | ||
|
||
it('exception thrown process run with array', function () { | ||
Process::fake(); | ||
|
||
Process::ssh([ | ||
'host' => '127.0.0.1', | ||
])->run(['ls', '-al']); | ||
|
||
})->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections.'); | ||
|
||
it('exception thrown process start with array', function () { | ||
Process::fake(); | ||
|
||
// it('timeout process', function () { | ||
// //Process::fake(); | ||
Process::ssh([ | ||
'host' => '127.0.0.1', | ||
])->start(['ls', '-al']); | ||
|
||
// $process = Process::ssh([ | ||
// 'host' => '192.168.8.5', | ||
// 'user' => 'ubuntu', | ||
// //'password' => 'password', | ||
// 'port' => 22, | ||
// ]) | ||
// ->run('ls'); | ||
})->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections.'); | ||
|
||
// dump($process->errorOutput()); | ||
// dump($process->output()); | ||
it('invoke process::pipe', function () { | ||
Process::fake(); | ||
|
||
// })->only(); | ||
$process = Process::ssh($this->basicSshConfig)->pipe([ | ||
'ls -al', | ||
'whoami', | ||
]); | ||
})->throws(InvalidArgumentException::class, 'Cannot pipe processes with SSH enabled.'); |