Skip to content

Commit

Permalink
Adds cli test for cleaning the orphaned remote storage
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamgurung committed Oct 29, 2021
1 parent 5de055c commit 44db268
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,9 @@ public function usingServer(?string $server):string {
$this->baseUrl = $this->remoteBaseUrl;
$this->currentServer = 'REMOTE';
}
echo "\n";
echo "$this->currentServer = ";
echo "$this->baseUrl \n";
return $previousServer;
}

Expand Down
57 changes: 53 additions & 4 deletions tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ public function deleteSystemConfigKeyUsingTheOccCommand(string $key):void {
);
}

/**
*
* @return void
* @throws Exception
*/
public function cleanOrphanedRemoteStoragesUsingOccCommand():void {
$this->invokingTheCommand(
"sharing:cleanup-remote-storages"
);
}

/**
* @param string $user
*
Expand Down Expand Up @@ -956,6 +967,33 @@ public function theOccCommandJsonOutputShouldNotReturnAnyData():void {
);
}

/**
* @Then :noOfOrphanedShare orphaned remote storage should have been cleared
*
* @param int $noOfOrphanedShare
*
* @return void
* @throws Exception
*/
public function theOrphanedRemoteStorageShouldBeCleared(int $noOfOrphanedShare):void {
$this->theCommandShouldHaveBeenSuccessful();
$commandOutput = $this->featureContext->getStdOutOfOccCommand();
// removing blank lines
$commandOutput = implode("\n", array_filter(explode("\n", $commandOutput)));
// splitting strings based on newline into an array
$outputLines = preg_split("/\r\n|\n|\r/", $commandOutput);
// calculating total no of shares deleted from remote storage: first getting total length of the array
// then minus 2 for first two lines of scan info message
// then divide by 2 because each share delete has message of two line
$totalSharesDeleted = (\count($outputLines) - 2) / 2;
var_dump($outputLines);
Assert::assertEquals(
$noOfOrphanedShare,
$totalSharesDeleted,
"The command should delete '$noOfOrphanedShare' orphaned shares but it deletes '$totalSharesDeleted' orphaned shares."
);
}

/**
* @Given the administrator has set the default folder for received shares to :folder
*
Expand Down Expand Up @@ -988,6 +1026,7 @@ public function theAdministratorHasSetTheDefaultFolderForReceivedSharesTo(string
* @param int $depth_infinity_allowed
*
* @return void
* @throws Exception
*/
public function theAdministratorHasSetDepthInfinityAllowedTo($depth_infinity_allowed) {
$this->addSystemConfigKeyUsingTheOccCommand(
Expand Down Expand Up @@ -2208,10 +2247,10 @@ public function administratorHasDeletedLocalStorageFolderUsingTheOccCommand(stri
* @param string $folder
* @param bool $mustExist
*
* @return integer
* @return integer|bool
* @throws Exception
*/
public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mustExist = true):int {
public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mustExist = true) {
$createdLocalStorage = [];
$this->listLocalStorageMount();
$commandOutput = \json_decode($this->featureContext->getStdOutOfOccCommand());
Expand Down Expand Up @@ -2532,6 +2571,16 @@ public function theAdministratorDeletesAllTheVersionsForUser(string $user):void
$this->deleteAllVersionsForUserUsingOccCommand($user);
}

/**
* @When the administrator cleanups all the orphaned remote storages of shares
*
* @return void
* @throws Exception
*/
public function theAdministratorCleanupsAllTheOrphanedRemoteStoragesOfShares():void {
$this->cleanOrphanedRemoteStoragesUsingOccCommand();
}

/**
* @When the administrator deletes all the versions for the following users:
*
Expand Down Expand Up @@ -2793,10 +2842,10 @@ public function theAdministratorHasClearedTheVersionsForAllUsers():void {
*
* @param string $job
*
* @return string
* @return string|bool
* @throws Exception
*/
public function getLastJobIdForJob(string $job):string {
public function getLastJobIdForJob(string $job) {
$this->getAllJobsInBackgroundQueueUsingOccCommand();
$commandOutput = $this->featureContext->getStdOutOfOccCommand();
$lines = SetupHelper::findLines(
Expand Down
27 changes: 27 additions & 0 deletions tests/acceptance/features/cliExternalStorage/Sharing.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@cli @api @federation-app-required @files_sharing-app-required
Feature:
As a admin
I want to cleanup orphaned remote storages
So that users will not get undesirable failure

Background:
Given using server "REMOTE"
And user "Alice" has been created with default attributes and without skeleton files
And using server "LOCAL"
And user "Brian" has been created with default attributes and without skeleton files

Scenario Outline: Clean up the orphaned remote storage after deleting the original shares
Given using OCS API version "<ocs-api-version>"
And using server "REMOTE"
And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Alice" from server "REMOTE" has shared "/textfile0.txt" with user "Brian" from server "LOCAL"
And user "Brian" from server "LOCAL" has accepted the last pending share
And user "Alice" has deleted the last share
And using server "LOCAL"
When the administrator cleanups all the orphaned remote storages of shares
Then 1 orphaned remote storage should have been cleared

Examples:
| ocs-api-version |
| 1 |
| 2 |

0 comments on commit 44db268

Please sign in to comment.