add test to restart upload sessions
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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user