2026-07-16 14:19:29 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
use App\Services\External\SelfRenderLivenessProbe;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
uses(TestCase::class);
|
|
|
|
|
|
|
|
|
|
it('серый, когда endpoint/health не заданы', function () {
|
|
|
|
|
config()->set('services.self_render.endpoint', '');
|
|
|
|
|
config()->set('services.self_render.health_url', '');
|
|
|
|
|
expect((new SelfRenderLivenessProbe)->check()->light)->toBe('grey');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('зелёный при 200', function () {
|
|
|
|
|
config()->set('services.self_render.health_url', 'https://vm.local/health');
|
|
|
|
|
Http::fake(['vm.local/health' => Http::response('ok', 200)]);
|
|
|
|
|
expect((new SelfRenderLivenessProbe)->check()->light)->toBe('green');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('красный при 500 и при сетевой ошибке', function () {
|
|
|
|
|
config()->set('services.self_render.health_url', 'https://vm.local/health');
|
|
|
|
|
Http::fake(['vm.local/health' => Http::response('err', 500)]);
|
|
|
|
|
expect((new SelfRenderLivenessProbe)->check()->light)->toBe('red');
|
|
|
|
|
Http::fake(fn () => throw new RuntimeException('down'));
|
|
|
|
|
expect((new SelfRenderLivenessProbe)->check()->light)->toBe('red');
|
|
|
|
|
});
|
2026-07-16 15:29:07 +03:00
|
|
|
|
|
|
|
|
it('зелёный при 404 (GET к POST-ручке — сервис жив)', function () {
|
|
|
|
|
config()->set('services.self_render.health_url', 'https://vm.local/render');
|
|
|
|
|
Http::fake(['vm.local/render' => Http::response('Not Found', 404)]);
|
|
|
|
|
expect((new SelfRenderLivenessProbe)->check()->light)->toBe('green');
|
|
|
|
|
});
|