Files
portal/app/tests/Unit/External/ExaTunnelLivenessProbeTest.php
T

35 lines
1.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Services\External\ExaTunnelLivenessProbe;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
uses(TestCase::class);
beforeEach(function () {
config()->set('services.exa.proxy', 'socks5h://127.0.0.1:10808');
config()->set('services.exa.tunnel_check_url', 'https://api.ipify.org');
});
it('серый, когда прокси-тоннель не настроен', function () {
config()->set('services.exa.proxy', '');
expect((new ExaTunnelLivenessProbe)->check()->light)->toBe('grey');
});
it('зелёный при 200 через прокси (тоннель жив)', function () {
Http::fake(['api.ipify.org*' => Http::response('1.2.3.4', 200)]);
$r = (new ExaTunnelLivenessProbe)->check();
expect($r->serviceKey)->toBe('exa_tunnel');
expect($r->light)->toBe('green');
});
it('красный при 500 и при сетевой ошибке (тоннель лёг)', function () {
Http::fake(['api.ipify.org*' => Http::response('err', 500)]);
expect((new ExaTunnelLivenessProbe)->check()->light)->toBe('red');
Http::fake(fn () => throw new RuntimeException('tunnel down'));
expect((new ExaTunnelLivenessProbe)->check()->light)->toBe('red');
});