Skip to content

Commit ae0a5e0

Browse files
committed
adds tess for logs cmds
1 parent f38d211 commit ae0a5e0

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

app/Commands/LogCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function logsByServiceNameOrContainerId(string $service, Collection $log
7171
{
7272
$containersByServiceName = $loggableContainers
7373
->filter(function ($containerName, $key) use ($service) {
74-
return Str::startsWith($containerName, $service) || $key === $service;
74+
return Str::startsWith($containerName, $service) || "{$key}" === $service;
7575
});
7676

7777
if ($containersByServiceName->isEmpty()) {

tests/Feature/LogCommandTest.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Shell\Docker;
6+
use Illuminate\Support\Collection;
7+
use Tests\TestCase;
8+
9+
class LogCommandTest extends TestCase
10+
{
11+
/** @test */
12+
function it_can_access_logss_from_a_service_from_menu()
13+
{
14+
$services = Collection::make([
15+
[
16+
'container_id' => $containerId = '12345',
17+
'names' => 'TO--mysql--8.0.22--3306',
18+
'status' => 'Up 27 minutes',
19+
'ports' => '0.0.0.0:3306->3306/tcp, 33060/tcp',
20+
'base_alias' => 'mysql',
21+
'full_alias' => 'mysql8.0',
22+
],
23+
]);
24+
25+
$this->mock(Docker::class, function ($mock) use ($services, $containerId) {
26+
$mock->shouldReceive('isInstalled')->andReturn(true);
27+
$mock->shouldReceive('isDockerServiceRunning')->andReturn(true);
28+
$mock->shouldReceive('activeTakeoutContainers')->andReturn($services, new Collection);
29+
$mock->shouldReceive('logContainer')->with($containerId);
30+
});
31+
32+
$this->artisan('logs')
33+
->expectsQuestion('Takeout containers logs', $containerId)
34+
->assertExitCode(0);
35+
}
36+
37+
/**
38+
* @test
39+
*
40+
* @testWith ["12345"]
41+
* ["mysql"]
42+
*
43+
*/
44+
public function it_can_access_logs_from_containers_by_service_name_or_id($arg)
45+
{
46+
$services = Collection::make([
47+
[
48+
'container_id' => $containerId = '12345',
49+
'names' => 'TO--mysql--8.0.22--3306',
50+
'status' => 'Up 27 minutes',
51+
'ports' => '0.0.0.0:3306->3306/tcp, 33060/tcp',
52+
'base_alias' => 'mysql',
53+
'full_alias' => 'mysql8.0',
54+
],
55+
]);
56+
57+
$this->mock(Docker::class, function ($mock) use ($services, $containerId) {
58+
$mock->shouldReceive('isInstalled')->andReturn(true);
59+
$mock->shouldReceive('isDockerServiceRunning')->andReturn(true);
60+
$mock->shouldReceive('activeTakeoutContainers')->andReturn($services, new Collection);
61+
$mock->shouldReceive('logContainer')->with($containerId);
62+
});
63+
64+
65+
$this->artisan('logs', ['containerId' => $arg])
66+
->assertExitCode(0);
67+
}
68+
}

tests/Feature/StopCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function it_can_stop_a_service_from_menu()
4141
* ["mysql"]
4242
*
4343
*/
44-
function it_can_stop_containers_by_service_name($arg)
44+
function it_can_stop_containers_by_service_name_or_id($arg)
4545
{
4646
$services = Collection::make([
4747
[

0 commit comments

Comments
 (0)