Skip to content

Commit 8fe4f82

Browse files
add cli tests for listing stale upload
1 parent 5e7d94f commit 8fe4f82

File tree

3 files changed

+148
-7
lines changed

3 files changed

+148
-7
lines changed

.drone.star

+14-7
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ pipelineVolumeGo = \
359359
"temp": {},
360360
}
361361

362+
storageVolume = \
363+
{
364+
"name": "storage",
365+
"path": "/root/.ocis",
366+
}
367+
362368
# minio mc environment variables
363369
MINIO_MC_ENV = {
364370
"CACHE_BUCKET": {
@@ -1036,7 +1042,7 @@ def localApiTestPipeline(ctx):
10361042
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
10371043
(tikaService() if params["tikaNeeded"] else []) +
10381044
(waitForServices("online-offices", ["collabora:9980", "onlyoffice:443", "fakeoffice:8080"]) if params["collaborationServiceNeeded"] else []) +
1039-
ocisServer(storage, params["accounts_hash_difficulty"], extra_server_environment = params["extraServerEnvironment"], with_wrapper = True, tika_enabled = params["tikaNeeded"]) +
1045+
ocisServer(storage, params["accounts_hash_difficulty"], extra_server_environment = params["extraServerEnvironment"], with_wrapper = True, tika_enabled = params["tikaNeeded"], volumes = ([storageVolume] if name.startswith("cli") else [])) +
10401046
(waitForClamavService() if params["antivirusNeeded"] else []) +
10411047
(waitForEmailService() if params["emailNeeded"] else []) +
10421048
(ocisServer(storage, params["accounts_hash_difficulty"], deploy_type = "federation", extra_server_environment = params["extraServerEnvironment"]) if params["federationServer"] else []) +
@@ -1055,6 +1061,10 @@ def localApiTestPipeline(ctx):
10551061
"refs/pull/**",
10561062
],
10571063
},
1064+
"volumes": [{
1065+
"name": "storage",
1066+
"temp": {},
1067+
}],
10581068
}
10591069
pipelines.append(pipeline)
10601070
return pipelines
@@ -1132,6 +1142,7 @@ def localApiTests(ctx, name, suites, storage = "ocis", extra_environment = {}, w
11321142
"" if with_remote_php else "cat %s/expected-failures-without-remotephp.md >> %s" % (test_dir, expected_failures_file),
11331143
"make -C %s test-acceptance-api" % (dirs["base"]),
11341144
],
1145+
"volumes": [storageVolume],
11351146
}]
11361147

11371148
def cs3ApiTests(ctx, storage, accounts_hash_difficulty = 4):
@@ -1537,12 +1548,8 @@ def multiServiceE2ePipeline(ctx):
15371548
for item in storage_users_environment:
15381549
storage_users2_environment[item] = storage_users_environment[item]
15391550

1540-
storage_volume = [{
1541-
"name": "storage",
1542-
"path": "/root/.ocis",
1543-
}]
1544-
storage_users_services = startOcisService("storage-users", "storageusers1", storage_users1_environment, storage_volume) + \
1545-
startOcisService("storage-users", "storageusers2", storage_users2_environment, storage_volume) + \
1551+
storage_users_services = startOcisService("storage-users", "storageusers1", storage_users1_environment, [storageVolume]) + \
1552+
startOcisService("storage-users", "storageusers2", storage_users2_environment, [storageVolume]) + \
15461553
ocisHealthCheck("storage-users", ["storageusers1:9159", "storageusers2:9159"])
15471554

15481555
for _, suite in config["e2eMultiService"].items():

tests/acceptance/bootstrap/CliContext.php

+84
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
2424
use Behat\Behat\Context\Context;
25+
use Behat\Gherkin\Node\PyStringNode;
2526
use Behat\Gherkin\Node\TableNode;
2627
use GuzzleHttp\Exception\GuzzleException;
2728
use PHPUnit\Framework\Assert;
@@ -496,4 +497,87 @@ public function theAdministratorTriggersEmailNotificationsUsingTheCLI(string $in
496497

497498
$this->featureContext->setResponse(CliHelper::runCommand($body));
498499
}
500+
501+
/**
502+
* @When the administrator has created stale upload
503+
*
504+
* @return void
505+
*/
506+
public function theAdministratorHasCreatedStaleUpload(): void {
507+
$folderPath = $this->featureContext->getStorageUsersRoot() . "/uploads";
508+
$infoFiles = glob($folderPath . '/*.info');
509+
foreach ($infoFiles as $file) {
510+
if (!unlink($file)) {
511+
Assert::fail("Fail to delete info file");
512+
}
513+
}
514+
}
515+
516+
/**
517+
* Runs the stale uploads CLI command
518+
*
519+
* @param bool $dryRun
520+
* @param string|null $spaceId
521+
*
522+
* @return void
523+
*/
524+
protected function runDeleteStaleUploadsCommand(bool $dryRun=true, ?string $spaceId = null): void {
525+
$command = "storage-users uploads delete-stale-nodes";
526+
$command .= " --dry-run=" . ($dryRun ? "true" : "false");
527+
528+
if ($spaceId !== null) {
529+
$command .= " --spaceid=$spaceId";
530+
}
531+
532+
$body = [
533+
"command" => $command
534+
];
535+
$this->featureContext->setResponse(CliHelper::runCommand($body));
536+
}
537+
538+
/**
539+
* @When the administrator lists all the stale uploads
540+
*
541+
* @return void
542+
*/
543+
public function theAdministratorListsAllTheStaleUploads(): void {
544+
$this->runDeleteStaleUploadsCommand(true);
545+
}
546+
547+
/**
548+
* @When the administrator lists the stale uploads of space :space owned by user :user
549+
*
550+
* @param string $spaceName
551+
* @param string $user
552+
*
553+
* @return void
554+
*/
555+
public function theAdministratorListsTheStaleUploadsOfSpace(string $spaceName, string $user): void {
556+
$space = $this->spacesContext->getSpaceByName(
557+
$user,
558+
$spaceName
559+
);
560+
$spaceOwnerId = $space["owner"]["user"]["id"];
561+
$this->runDeleteStaleUploadsCommand(true, $spaceOwnerId);
562+
}
563+
564+
/**
565+
* @Then the CLI response should contain these message:
566+
*
567+
* @param PyStringNode $content
568+
*
569+
* @return void
570+
*/
571+
public function theCLIResponseShouldContainTheseMessage(PyStringNode $content): void {
572+
$response = $this->featureContext->getJsonDecodedResponseBodyContent();
573+
$this->featureContext->theHTTPStatusCodeShouldBe(200);
574+
$expectedMessage = str_replace("\r\n", "\n", trim($content->getRaw()));
575+
$actualMessage = str_replace("\r\n", "\n", trim($response->message ?? ''));
576+
577+
Assert::assertSame(
578+
$expectedMessage,
579+
$actualMessage,
580+
"Expected cli output to be $expectedMessage but found $actualMessage"
581+
);
582+
}
499583
}

tests/acceptance/features/cliCommands/uploadSessions.feature

+50
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,53 @@ Feature: List upload sessions via CLI command
151151
And the CLI response should not contain these entries:
152152
| file1.txt |
153153
| virusFile.txt |
154+
155+
156+
Scenario: list all stale uploads
157+
Given the config "POSTPROCESSING_DELAY" has been set to "10s"
158+
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
159+
And user "Alice" has created a space "staleuploads" with the default quota using the Graph API
160+
And user "Brian" has been created with default attributes
161+
And user "Alice" has uploaded a file "filesForUpload/testavatar.jpg" to "/testavatar.jpg" in space "staleuploads"
162+
And user "Brian" has uploaded file "filesForUpload/textfile.txt" to "textfile.txt"
163+
And the administrator has stopped the server
164+
And the administrator has created stale upload
165+
And the administrator has started the server
166+
When the administrator lists all the stale uploads
167+
Then the CLI response should contain these message:
168+
"""
169+
Scanning all spaces for stale processing nodes...
170+
Total stale nodes: 2
171+
"""
172+
173+
174+
Scenario: list stale upload of specific space
175+
Given user "Brian" has been created with default attributes
176+
And user "Alice" has created folder "FolderToShare"
177+
And using spaces DAV path
178+
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
179+
And user "Alice" has created a space "staleuploads" with the default quota using the Graph API
180+
And using SharingNG
181+
And the config "POSTPROCESSING_DELAY" has been set to "10s"
182+
And user "Alice" has sent the following resource share invitation:
183+
| resource | FolderToShare |
184+
| space | Personal |
185+
| sharee | Brian |
186+
| shareType | user |
187+
| permissionsRole | Uploader |
188+
And user "Brian" has uploaded a file "filesForUpload/testavatar.png" to "FolderToShare/testavatar.png" in space "Shares"
189+
And user "Alice" has uploaded file "filesForUpload/testavatar.png" to "testavatar.png"
190+
And user "Alice" has uploaded a file "filesForUpload/testavatar.jpg" to "/testavatar.jpg" in space "staleuploads"
191+
And the administrator has stopped the server
192+
And the administrator has created stale upload
193+
And the administrator has started the server
194+
When the administrator lists the stale uploads of space "Personal" owned by user "Alice"
195+
Then the CLI response should contain these message:
196+
"""
197+
Total stale nodes: 2
198+
"""
199+
When the administrator lists the stale uploads of space "staleuploads" owned by user "Alice"
200+
Then the CLI response should contain these message:
201+
"""
202+
Total stale nodes: 1
203+
"""

0 commit comments

Comments
 (0)