diff options
author | Joas Schilling <coding@schilljs.com> | 2024-05-12 16:33:34 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-07-30 13:18:09 +0200 |
commit | 710a69b4b5c81262da3c2f4efff10a87356598d0 (patch) | |
tree | d4bebe834292cfcdce94e0058e0b9d65f1201c7f /tests | |
parent | 21f558b12bdb985ec312ac8973f2be9c0d73f824 (diff) | |
download | nextcloud-server-710a69b4b5c81262da3c2f4efff10a87356598d0.tar.gz nextcloud-server-710a69b4b5c81262da3c2f4efff10a87356598d0.zip |
feat(log): Allow to combine log.conditions to only log (app&user)
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/LoggerTest.php | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php index e3a51d93804..6343ce62065 100644 --- a/tests/lib/LoggerTest.php +++ b/tests/lib/LoggerTest.php @@ -10,6 +10,8 @@ namespace Test; use OC\Log; use OC\SystemConfig; use OCP\ILogger; +use OCP\IUser; +use OCP\IUserSession; use OCP\Log\IWriter; use OCP\Support\CrashReport\IRegistry; use PHPUnit\Framework\MockObject\MockObject; @@ -73,6 +75,94 @@ class LoggerTest extends TestCase implements IWriter { $this->assertEquals($expected, $this->getLogs()); } + public function dataMatchesCondition(): array { + return [ + [ + 'user0', + [ + 'apps' => ['app2'], + ], + [ + '1 Info of app2', + ], + ], + [ + 'user2', + [ + 'users' => ['user1', 'user2'], + 'apps' => ['app1'], + ], + [ + '1 Info of app1', + ], + ], + [ + 'user3', + [ + 'users' => ['user3'], + ], + [ + '1 Info without app', + '1 Info of app1', + '1 Info of app2', + '0 Debug of app3', + ], + ], + [ + 'user4', + [ + 'users' => ['user4'], + 'apps' => ['app3'], + 'loglevel' => 0, + ], + [ + '0 Debug of app3', + ], + ], + [ + 'user4', + [ + 'message' => ' of ', + ], + [ + '1 Info of app1', + '1 Info of app2', + '0 Debug of app3', + ], + ], + ]; + } + + /** + * @dataProvider dataMatchesCondition + */ + public function testMatchesCondition(string $userId, array $conditions, array $expectedLogs): void { + $this->config->expects($this->any()) + ->method('getValue') + ->willReturnMap([ + ['loglevel', ILogger::WARN, ILogger::WARN], + ['log.condition', [], ['matches' => [ + $conditions, + ]]], + ]); + $logger = $this->logger; + + $user = $this->createMock(IUser::class); + $user->method('getUID') + ->willReturn($userId); + $userSession = $this->createMock(IUserSession::class); + $userSession->method('getUser') + ->willReturn($user); + $this->overwriteService(IUserSession::class, $userSession); + + $logger->info('Info without app'); + $logger->info('Info of app1', ['app' => 'app1']); + $logger->info('Info of app2', ['app' => 'app2']); + $logger->debug('Debug of app3', ['app' => 'app3']); + + $this->assertEquals($expectedLogs, $this->getLogs()); + } + public function testLoggingWithDataArray(): void { $this->mockDefaultLogLevel(); $writerMock = $this->createMock(IWriter::class); |