37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
use App\Services\External\KeysoLivenessProbe;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
beforeEach(fn () => config()->set('services.keyso.base_url', 'https://api.keys.so'));
|
|
|
|
it('зелёный при 200', function () {
|
|
Http::fake(['api.keys.so/*' => Http::response('ok', 200)]);
|
|
expect((new KeysoLivenessProbe)->check()->light)->toBe('green');
|
|
});
|
|
|
|
it('зелёный при 404 (хост достучались — keys.so жив)', function () {
|
|
Http::fake(['api.keys.so/*' => Http::response('Not Found', 404)]);
|
|
expect((new KeysoLivenessProbe)->check()->light)->toBe('green');
|
|
});
|
|
|
|
it('красный при 5xx и при обрыве', function () {
|
|
Http::fake(['api.keys.so/*' => Http::response('err', 503)]);
|
|
expect((new KeysoLivenessProbe)->check()->light)->toBe('red');
|
|
Http::fake(fn () => throw new RuntimeException('down'));
|
|
expect((new KeysoLivenessProbe)->check()->light)->toBe('red');
|
|
});
|
|
|
|
it('серый, когда base_url пуст', function () {
|
|
config()->set('services.keyso.base_url', '');
|
|
expect((new KeysoLivenessProbe)->check()->light)->toBe('grey');
|
|
});
|
|
|
|
it('serviceKey = keyso', function () {
|
|
expect((new KeysoLivenessProbe)->serviceKey())->toBe('keyso');
|
|
});
|