diff options
author | Robin Appelman <robin@icewind.nl> | 2022-01-21 14:09:45 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-03-04 18:01:16 +0100 |
commit | 6cd8f727f0755fd61607a332f1f3cecdba62bf5b (patch) | |
tree | 3cb45c4a4ec5860c8708bd2778f290c8494b6d09 | |
parent | 8ae4a3298edfd521d1c0c8b1d144923cf654266c (diff) | |
download | nextcloud-server-smb-notify-test.tar.gz nextcloud-server-smb-notify-test.zip |
test: improve notify tests for smbsmb-notify-test
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/files_external/tests/Storage/SmbTest.php | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php index 30040e499c8..cc6b7729a59 100644 --- a/apps/files_external/tests/Storage/SmbTest.php +++ b/apps/files_external/tests/Storage/SmbTest.php @@ -105,6 +105,7 @@ class SmbTest extends \Test\Files\Storage\Storage { $this->instance->unlink('/renamed.txt'); sleep(1); //time for all changes to be processed + /** @var IChange[] $changes */ $changes = []; $count = 0; // wait up to 10 seconds for incoming changes @@ -115,14 +116,23 @@ class SmbTest extends \Test\Files\Storage\Storage { } $notifyHandler->stop(); - $expected = [ - new Change(IChange::ADDED, 'newfile.txt'), - new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), - new Change(IChange::REMOVED, 'renamed.txt') - ]; + // depending on the server environment, the initial create might be detected as a change instead + if ($changes[0]->getType() === IChange::MODIFIED) { + $expected = [ + new Change(IChange::MODIFIED, 'newfile.txt'), + new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), + new Change(IChange::REMOVED, 'renamed.txt') + ]; + } else { + $expected = [ + new Change(IChange::ADDED, 'newfile.txt'), + new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), + new Change(IChange::REMOVED, 'renamed.txt') + ]; + } foreach ($expected as $expectedChange) { - $this->assertTrue(in_array($expectedChange, $changes), 'Actual changes are:' . PHP_EOL . print_r($changes, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true)); + $this->assertTrue(in_array($expectedChange, $changes), "Expected changes are:\n" . print_r($changes, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true) . "\nGot:\n" . print_r($changes, true)); } } @@ -141,7 +151,12 @@ class SmbTest extends \Test\Files\Storage\Storage { return false;//stop listening }); - $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result); + // depending on the server environment, the initial create might be detected as a change instead + if ($result->getType() === IChange::ADDED) { + $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result); + } else { + $this->assertEquals(new Change(IChange::MODIFIED, 'newfile.txt'), $result); + } } public function testRenameRoot() { |