37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
use App\Services\External\XfetchLivenessProbe;
|
||
|
|
use Illuminate\Support\Facades\Http;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
uses(TestCase::class);
|
||
|
|
|
||
|
|
beforeEach(fn () => config()->set('services.xfetch.endpoint', 'https://xf4.ru/fetch'));
|
||
|
|
|
||
|
|
it('зелёный при 200', function () {
|
||
|
|
Http::fake(['xf4.ru/*' => Http::response('ok', 200)]);
|
||
|
|
expect((new XfetchLivenessProbe)->check()->light)->toBe('green');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('зелёный при 405 (GET к POST-ручке — сервис отвечает)', function () {
|
||
|
|
Http::fake(['xf4.ru/*' => Http::response('method not allowed', 405)]);
|
||
|
|
expect((new XfetchLivenessProbe)->check()->light)->toBe('green');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('красный при 5xx и при обрыве', function () {
|
||
|
|
Http::fake(['xf4.ru/*' => Http::response('err', 502)]);
|
||
|
|
expect((new XfetchLivenessProbe)->check()->light)->toBe('red');
|
||
|
|
Http::fake(fn () => throw new RuntimeException('down'));
|
||
|
|
expect((new XfetchLivenessProbe)->check()->light)->toBe('red');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('серый, когда endpoint пуст', function () {
|
||
|
|
config()->set('services.xfetch.endpoint', '');
|
||
|
|
expect((new XfetchLivenessProbe)->check()->light)->toBe('grey');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('serviceKey = xfetch', function () {
|
||
|
|
expect((new XfetchLivenessProbe)->serviceKey())->toBe('xfetch');
|
||
|
|
});
|