-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split adapters into separate tests for better maintainability
- Loading branch information
1 parent
81aba34
commit ddf6f6f
Showing
12 changed files
with
447 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\E2E\Adapter; | ||
|
||
use Utopia\Logger\Adapter\AppSignal; | ||
use Utopia\Tests\E2E\AdapterBase; | ||
|
||
class AppSignalTest extends AdapterBase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$appSignalKey = \getenv('TEST_APPSIGNAL_KEY'); | ||
$this->adapter = new AppSignal($appSignalKey ? $appSignalKey : ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\E2E\Adapter; | ||
|
||
use Utopia\Logger\Adapter\LogOwl; | ||
use Utopia\Tests\E2E\AdapterBase; | ||
|
||
class LogOwlTest extends AdapterBase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$logOwlKey = \getenv('TEST_LOGOWL_KEY'); | ||
$this->adapter = new LogOwl($logOwlKey ? $logOwlKey : ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\E2E\Adapter; | ||
|
||
use Utopia\Logger\Adapter\Raygun; | ||
use Utopia\Tests\E2E\AdapterBase; | ||
|
||
class RaygunTest extends AdapterBase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$raygunKey = \getenv('TEST_RAYGUN_KEY'); | ||
$this->adapter = new Raygun($raygunKey ? $raygunKey : ''); | ||
$this->expected = 202; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\E2E\Adapter; | ||
|
||
use Utopia\Logger\Adapter\Sentry; | ||
use Utopia\Tests\E2E\AdapterBase; | ||
|
||
class SentryTest extends AdapterBase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->adapter = new Sentry(\getenv('TEST_SENTRY_KEY').';'.\getenv('TEST_SENTRY_PROJECT_ID').';'.\getenv('TEST_SENTRY_HOST')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\E2E; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Utopia\Logger\Adapter; | ||
use Utopia\Logger\Log; | ||
use Utopia\Logger\Log\Breadcrumb; | ||
use Utopia\Logger\Log\User; | ||
use Utopia\Logger\Logger; | ||
|
||
abstract class AdapterBase extends TestCase | ||
{ | ||
protected ?Log $log = null; | ||
|
||
protected ?Adapter $adapter = null; | ||
|
||
protected int $expected = 200; | ||
|
||
protected function setUp(): void | ||
{ | ||
// Prepare log | ||
$this->log = new Log(); | ||
$this->log->setAction('controller.database.deleteDocument'); | ||
$this->log->setEnvironment('production'); | ||
$this->log->setNamespace('api'); | ||
$this->log->setServer('digitalocean-us-001'); | ||
$this->log->setType(Log::TYPE_ERROR); | ||
$this->log->setVersion('0.11.5'); | ||
$this->log->setMessage('Document efgh5678 not found'); | ||
$this->log->setUser(new User('efgh5678')); | ||
$this->log->addBreadcrumb(new Breadcrumb(Log::TYPE_DEBUG, 'http', 'DELETE /api/v1/database/abcd1234/efgh5678', \microtime(true) - 500)); | ||
$this->log->addBreadcrumb(new Breadcrumb(Log::TYPE_DEBUG, 'auth', 'Using API key', \microtime(true) - 400)); | ||
$this->log->addBreadcrumb(new Breadcrumb(Log::TYPE_INFO, 'auth', 'Authenticated with * Using API Key', \microtime(true) - 350)); | ||
$this->log->addBreadcrumb(new Breadcrumb(Log::TYPE_INFO, 'database', 'Found collection abcd1234', \microtime(true) - 300)); | ||
$this->log->addBreadcrumb(new Breadcrumb(Log::TYPE_DEBUG, 'database', 'Permission for collection abcd1234 met', \microtime(true) - 200)); | ||
$this->log->addBreadcrumb(new Breadcrumb(Log::TYPE_ERROR, 'database', 'Missing document when searching by ID!', \microtime(true))); | ||
$this->log->addTag('sdk', 'Flutter'); | ||
$this->log->addTag('sdkVersion', '0.0.1'); | ||
$this->log->addTag('authMode', 'default'); | ||
$this->log->addTag('authMethod', 'cookie'); | ||
$this->log->addTag('authProvider', 'MagicLink'); | ||
$this->log->addExtra('urgent', false); | ||
$this->log->addExtra('isExpected', true); | ||
$this->log->addExtra('file', '/User/example/server/src/server/server.js'); | ||
$this->log->addExtra('line', '15'); | ||
} | ||
|
||
/** | ||
* @throws \Throwable | ||
*/ | ||
public function testAdapter(): void | ||
{ | ||
if (empty($this->log) || empty($this->adapter)) { | ||
throw new \Exception('Log or adapter not set'); | ||
} | ||
$logger = new Logger($this->adapter); | ||
$response = $logger->addLog($this->log); | ||
$this->assertEquals($this->expected, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\Unit\Log; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Utopia\Logger\Log; | ||
use Utopia\Logger\Log\Breadcrumb; | ||
|
||
class BreadcrumbTest extends TestCase | ||
{ | ||
/** | ||
* @throws \Throwable | ||
*/ | ||
public function testLogBreadcrumb(): void | ||
{ | ||
$timestamp = \microtime(true); | ||
$breadcrumb = new Breadcrumb(Log::TYPE_DEBUG, 'http', 'POST /user', $timestamp); | ||
|
||
self::assertEquals(Log::TYPE_DEBUG, $breadcrumb->getType()); | ||
self::assertEquals('http', $breadcrumb->getCategory()); | ||
self::assertEquals('POST /user', $breadcrumb->getMessage()); | ||
self::assertEquals($timestamp, $breadcrumb->getTimestamp()); | ||
|
||
$breadcrumb = new Breadcrumb(Log::TYPE_INFO, 'http', 'POST /user', $timestamp); | ||
self::assertEquals(Log::TYPE_INFO, $breadcrumb->getType()); | ||
$breadcrumb = new Breadcrumb(Log::TYPE_VERBOSE, 'http', 'POST /user', $timestamp); | ||
self::assertEquals(Log::TYPE_VERBOSE, $breadcrumb->getType()); | ||
$breadcrumb = new Breadcrumb(Log::TYPE_ERROR, 'http', 'POST /user', $timestamp); | ||
self::assertEquals(Log::TYPE_ERROR, $breadcrumb->getType()); | ||
$breadcrumb = new Breadcrumb(Log::TYPE_WARNING, 'http', 'POST /user', $timestamp); | ||
self::assertEquals(Log::TYPE_WARNING, $breadcrumb->getType()); | ||
|
||
// Assert FAILS | ||
self::expectException(\ArgumentCountError::class); | ||
$breadcrumb = new Breadcrumb(); // @phpstan-ignore-line | ||
$breadcrumb = new Breadcrumb(Log::TYPE_DEBUG); // @phpstan-ignore-line | ||
$breadcrumb = new Breadcrumb(Log::TYPE_DEBUG, 'http'); // @phpstan-ignore-line | ||
$breadcrumb = new Breadcrumb(Log::TYPE_DEBUG, 'http', 'POST /user'); // @phpstan-ignore-line | ||
} | ||
} |
Oops, something went wrong.