aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-06 16:11:18 +0100
committerRobin Appelman <robin@icewind.nl>2017-01-27 10:44:41 +0100
commit72eeb8fd2267f1a4d319372c455e3fbd0539976f (patch)
tree09fdb5ca06569de6416ae8b8d337fe9af90d8c04 /apps/files_external
parentc7536f787748a067c250c917d2fdb0d807d73a50 (diff)
downloadnextcloud-server-72eeb8fd2267f1a4d319372c455e3fbd0539976f.tar.gz
nextcloud-server-72eeb8fd2267f1a4d319372c455e3fbd0539976f.zip
add notify self test
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/Command/Notify.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/apps/files_external/lib/Command/Notify.php b/apps/files_external/lib/Command/Notify.php
index b317f5c0594..a55b16a45c4 100644
--- a/apps/files_external/lib/Command/Notify.php
+++ b/apps/files_external/lib/Command/Notify.php
@@ -28,8 +28,10 @@ use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\GlobalStoragesService;
use OCP\Files\Notify\IChange;
+use OCP\Files\Notify\INotifyHandler;
use OCP\Files\Notify\IRenameChange;
use OCP\Files\Storage\INotifyStorage;
+use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
use Symfony\Component\Console\Input\InputArgument;
@@ -125,7 +127,9 @@ class Notify extends Base {
$verbose = $input->getOption('verbose');
$path = trim($input->getOption('path'), '/');
- $storage->notify($path)->listen(function (IChange $change) use ($mount, $verbose, $output) {
+ $notifyHandler = $storage->notify($path);
+ $this->selfTest($storage, $notifyHandler, $verbose, $output);
+ $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
if ($verbose) {
$this->logUpdate($change, $output);
}
@@ -174,4 +178,35 @@ class Notify extends Base {
$output->writeln($text);
}
+
+ private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
+ usleep(100 * 1000); //give time for the notify to start
+ $storage->file_put_contents('/.nc_test_file.txt', 'test content');
+ $storage->mkdir('/.nc_test_folder');
+ $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
+ $storage->unlink('/.nc_test_file.txt');
+ $storage->unlink('/.nc_test_folder/subfile.txt');
+ $storage->rmdir('/.nc_test_folder');
+ usleep(100 * 1000); //time for all changes to be processed
+
+ $foundRootChange = false;
+ $foundSubfolderChange = false;
+
+ $changes = $notifyHandler->getChanges();
+ foreach ($changes as $change) {
+ if ($change->getPath() === '/.nc_test_file.txt') {
+ $foundRootChange = true;
+ } else if ($change->getPath() === '/.nc_test_folder/subfile.txt') {
+ $foundSubfolderChange = true;
+ }
+ }
+
+ if ($foundRootChange && $foundSubfolderChange && $verbose) {
+ $output->writeln('<info>Self-test successful</info>');
+ } else if ($foundRootChange && !$foundSubfolderChange) {
+ $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
+ } else if (!$foundRootChange) {
+ $output->writeln('<error>Error while running self-test, no changes detected</error>');
+ }
+ }
}