mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-18 03:18:52 -06:00
Merge pull request #10256 from owncloud/restart-upload-sessions
[tests-only][full-ci] added test to restart upload sessions using CLI command
This commit is contained in:
@@ -27,6 +27,7 @@ use PHPUnit\Framework\Assert;
|
||||
use TestHelpers\CliHelper;
|
||||
use TestHelpers\OcisConfigHelper;
|
||||
use TestHelpers\BehatHelper;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* CLI context
|
||||
@@ -268,6 +269,45 @@ class CliContext implements Context {
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator restarts the upload sessions that are in postprocessing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorRestartsTheUploadSessionsThatAreInPostprocessing(): void {
|
||||
$command = "storage-users uploads sessions --processing --restart --json";
|
||||
$body = [
|
||||
"command" => $command
|
||||
];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator restarts the upload sessions of file :file
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function theAdministratorRestartsUploadSessionsOfFile(string $file): void {
|
||||
$response = CliHelper::runCommand(["command" => "storage-users uploads sessions --json"]);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
|
||||
$responseArray = $this->getJSONDecodedCliMessage($response);
|
||||
|
||||
foreach ($responseArray as $item) {
|
||||
if ($item->filename === $file) {
|
||||
$uploadId = $item->id;
|
||||
}
|
||||
}
|
||||
|
||||
$command = "storage-users uploads sessions --id=$uploadId --restart --json";
|
||||
$body = [
|
||||
"command" => $command
|
||||
];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the CLI response (should|should not) contain these entries:$/
|
||||
*
|
||||
@@ -275,16 +315,11 @@ class CliContext implements Context {
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function theCLIResponseShouldContainTheseEntries(string $shouldOrNot, TableNode $table): void {
|
||||
$expectedFiles = $table->getColumn(0);
|
||||
$responseBody = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse());
|
||||
|
||||
// $responseBody["message"] contains a message info with the array of output json of the upload sessions command
|
||||
// Example Output: "INFO memory is not limited, skipping package=github.com/KimMachineGun/automemlimit/memlimit [{<output-json>}]"
|
||||
// So, only extracting the array of output json from the message
|
||||
preg_match('/(\[.*\])/', $responseBody["message"], $matches);
|
||||
$responseArray = \json_decode($matches[1], null, 512, JSON_THROW_ON_ERROR);
|
||||
$responseArray = $this->getJSONDecodedCliMessage($this->featureContext->getResponse());
|
||||
|
||||
$resourceNames = [];
|
||||
foreach ($responseArray as $item) {
|
||||
@@ -310,6 +345,22 @@ class CliContext implements Context {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* @return array
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getJSONDecodedCliMessage(ResponseInterface $response): array {
|
||||
$responseBody = $this->featureContext->getJsonDecodedResponse($response);
|
||||
|
||||
// $responseBody["message"] contains a message info with the array of output json of the upload sessions command
|
||||
// Example Output: "INFO memory is not limited, skipping package=github.com/KimMachineGun/automemlimit/memlimit [{<output-json>}]"
|
||||
// So, only extracting the array of output json from the message
|
||||
\preg_match('/(\[.*\])/', $responseBody["message"], $matches);
|
||||
return \json_decode($matches[1], null, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @AfterScenario @cli-uploads-sessions
|
||||
*
|
||||
|
||||
@@ -8,7 +8,7 @@ Feature: List upload sessions via CLI command
|
||||
Given user "Alice" has been created with default attributes and without skeleton files
|
||||
|
||||
|
||||
Scenario: user lists all upload sessions
|
||||
Scenario: list all upload sessions
|
||||
Given user "Alice" has uploaded file with content "uploaded content" to "/file0.txt"
|
||||
And the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||
@@ -22,7 +22,7 @@ Feature: List upload sessions via CLI command
|
||||
| file0.txt |
|
||||
|
||||
|
||||
Scenario: user lists all upload sessions that are currently in postprocessing
|
||||
Scenario: list all upload sessions that are currently in postprocessing
|
||||
Given the following configs have been set:
|
||||
| config | value |
|
||||
| POSTPROCESSING_STEPS | virusscan |
|
||||
@@ -40,7 +40,7 @@ Feature: List upload sessions via CLI command
|
||||
| virusFile.txt |
|
||||
|
||||
|
||||
Scenario: user lists all upload sessions that are infected by virus
|
||||
Scenario: list all upload sessions that are infected by virus
|
||||
Given the following configs have been set:
|
||||
| config | value |
|
||||
| POSTPROCESSING_STEPS | virusscan |
|
||||
@@ -55,7 +55,7 @@ Feature: List upload sessions via CLI command
|
||||
| file1.txt |
|
||||
|
||||
|
||||
Scenario: user lists all expired upload sessions
|
||||
Scenario: list all expired upload sessions
|
||||
Given the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||
And the config "STORAGE_USERS_UPLOAD_EXPIRATION" has been set to "0"
|
||||
@@ -70,7 +70,7 @@ Feature: List upload sessions via CLI command
|
||||
| file1.txt |
|
||||
|
||||
|
||||
Scenario: user cleans all expired upload sessions
|
||||
Scenario: clean all expired upload sessions
|
||||
Given the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||
And user "Alice" has uploaded file with content "upload content" to "/file1.txt"
|
||||
And the config "STORAGE_USERS_UPLOAD_EXPIRATION" has been set to "0"
|
||||
@@ -83,3 +83,27 @@ Feature: List upload sessions via CLI command
|
||||
| file3.txt |
|
||||
And the CLI response should not contain these entries:
|
||||
| file1.txt |
|
||||
|
||||
|
||||
Scenario: restart upload sessions that are in postprocessing
|
||||
Given user "Alice" has uploaded file with content "upload content" to "/file1.txt"
|
||||
And the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||
And user "Alice" has uploaded file with content "upload content" to "/file2.txt"
|
||||
When the administrator restarts the upload sessions that are in postprocessing
|
||||
Then the command should be successful
|
||||
And the CLI response should contain these entries:
|
||||
| file2.txt |
|
||||
And the CLI response should not contain these entries:
|
||||
| file1.txt |
|
||||
|
||||
|
||||
Scenario: restart upload sessions of a single file
|
||||
Given the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||
And user "Alice" has uploaded file with content "upload content" to "/file1.txt"
|
||||
And user "Alice" has uploaded file with content "upload content" to "/file2.txt"
|
||||
When the administrator restarts the upload sessions of file "file1.txt"
|
||||
Then the command should be successful
|
||||
And the CLI response should contain these entries:
|
||||
| file1.txt |
|
||||
And the CLI response should not contain these entries:
|
||||
| file2.txt |
|
||||
|
||||
Reference in New Issue
Block a user