Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] [full-ci] Adds cli test for cleaning the orphaned remote storage #39436

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 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,35 @@ 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);
// first line of command output contains total remote storage scanned
$totalRemoteStorage = (int) filter_var($outputLines[0], FILTER_SANITIZE_NUMBER_INT);
echo "totalremotestorage: $totalRemoteStorage";
// 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) / $totalRemoteStorage;
Assert::assertEquals(
$noOfOrphanedShare,
$totalSharesDeleted,
"The command was expected to delete '$noOfOrphanedShare' orphaned shares but only deleted '$totalSharesDeleted' orphaned shares."
);
}

/**
* @Given the administrator has set the default folder for received shares to :folder
*
Expand Down Expand Up @@ -988,6 +1028,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 +2249,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 +2573,16 @@ public function theAdministratorDeletesAllTheVersionsForUser(string $user):void
$this->deleteAllVersionsForUserUsingOccCommand($user);
}

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

/**
* @When the administrator deletes all the versions for the following users:
*
Expand Down Expand Up @@ -2793,10 +2844,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 using the occ command
Then 1 orphaned remote storage should have been cleared

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