Files
appwrite/tests/e2e/Scopes/RequiresDocumentsDB.php
Prem Palanisamy 206d313da1 fix: skip VectorsDB/DocumentsDB database tests when backend unavailable
Add RequiresVectorsDB and RequiresDocumentsDB traits that probe the
database create endpoint once per test class and call markTestSkipped
when the backend returns a 500 error. This handles CI environments
where COMPOSE_PROFILES only starts a single database service.

Applied to all VectorsDB test classes (need PostgreSQL) and all
DocumentsDB test classes (need MongoDB): main tests, permissions
tests, and transaction tests. Also added a fallback guard in the
shared DatabasesBase::setupDatabase() method.
2026-03-30 19:25:05 +01:00

46 lines
1.5 KiB
PHP

<?php
namespace Tests\E2E\Scopes;
use Tests\E2E\Client;
use Utopia\Database\Helpers\ID;
/**
* Trait that skips the entire test class when the DocumentsDB backend
* (MongoDB) is not reachable. Uses a single probe request per
* class, cached in a static flag.
*/
trait RequiresDocumentsDB
{
private static ?bool $documentsDBAvailable = null;
protected function setUp(): void
{
parent::setUp();
if (self::$documentsDBAvailable === null) {
$response = $this->client->call(Client::METHOD_POST, '/documentsdb', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'databaseId' => ID::custom('documentsdb-probe'),
'name' => 'Probe',
]);
self::$documentsDBAvailable = $response['headers']['status-code'] < 500;
if (self::$documentsDBAvailable) {
$this->client->call(Client::METHOD_DELETE, '/documentsdb/documentsdb-probe', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]);
}
}
if (!self::$documentsDBAvailable) {
$this->markTestSkipped('DocumentsDB backend (MongoDB) is not available in this CI environment.');
}
}
}