[tests-only][full-ci] test(cli): add blobstore get and check CLI tests (#12505)
* test(cli): add blobstore check and get CLI test scenarios * ci: add get blob step * test(cli): add valid blob size, --path, by-ID, and malformed path blobstore tests * test: include round-trip verifications * test: swap check assertions from exact-match to substring-contains
This commit is contained in:
1 parent
afa8790227
commit
58a0bd9dea
2 files changed
+203
-2
No files matched your search
@@ -756,10 +756,10 @@ class CliContext implements Context {
|
||||
$expectedMessage = str_replace("\r\n", "\n", trim($content->getRaw()));
|
||||
$actualMessage = str_replace("\r\n", "\n", trim($response->message ?? ''));
|
||||
|
||||
Assert::assertSame(
|
||||
Assert::assertStringContainsString(
|
||||
$expectedMessage,
|
||||
$actualMessage,
|
||||
"Expected cli output to be $expectedMessage but found $actualMessage",
|
||||
"Expected cli output to contain '$expectedMessage', but got: '$actualMessage'",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1277,4 +1277,130 @@ class CliContext implements Context {
|
||||
|
||||
Assert::assertTrue($found, "Could not find blob for space $spaceName ($spaceOpaqueId)");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator checks the blobstore using the CLI
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorChecksTheBlobstoreUsingTheCli(): void {
|
||||
$body = ["command" => "storage-users blobstore check"];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator checks the blobstore with blob size :blobSize using the CLI
|
||||
*
|
||||
* @param string $blobSize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorChecksTheBlobstoreWithBlobSizeUsingTheCli(string $blobSize): void {
|
||||
$body = ["command" => "storage-users blobstore check --blob-size=$blobSize"];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator tries to get a blob from the blobstore using the CLI
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorTriesToGetABlobFromTheBlobstoreUsingTheCli(): void {
|
||||
$body = ["command" => "storage-users blobstore get"];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator tries to get a non-existent blob from the blobstore using the CLI
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorTriesToGetANonExistentBlobFromTheBlobstoreUsingTheCli(): void {
|
||||
$body = [
|
||||
"command" => "storage-users blobstore get"
|
||||
. " --blob-id=00000000-0000-0000-0000-000000000001"
|
||||
. " --space-id=00000000-0000-0000-0000-000000000002",
|
||||
];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the most recently written blob in the storage-users blobstore.
|
||||
* Scoped to the users storage root to avoid picking blobs from metadata storage.
|
||||
*
|
||||
* @return string absolute path to a real blob file
|
||||
*/
|
||||
private function findNewestBlobPath(): string {
|
||||
$storageRoot = $this->featureContext->getStorageUsersRoot();
|
||||
$blobDirs = \glob($storageRoot . '/spaces/*/*/blobs', GLOB_ONLYDIR) ?: [];
|
||||
Assert::assertNotEmpty($blobDirs, "No blobstore directory found under $storageRoot");
|
||||
|
||||
$newestPath = null;
|
||||
$newestMtime = 0;
|
||||
foreach ($blobDirs as $blobsDir) {
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($blobsDir, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
);
|
||||
foreach ($iterator as $file) {
|
||||
if (!$file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
$mtime = $file->getMTime();
|
||||
if ($mtime > $newestMtime) {
|
||||
$newestMtime = $mtime;
|
||||
$newestPath = $file->getPathname();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert::assertNotNull($newestPath, "No blob file found under $storageRoot");
|
||||
return $newestPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator gets a blob from the blobstore using the --path flag via the CLI
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorGetsABlobFromTheBlobstoreUsingThePathFlagViaTheCli(): void {
|
||||
$blobPath = $this->findNewestBlobPath();
|
||||
$body = ["command" => "storage-users blobstore get --path=" . $blobPath];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator tries to get a blob from the blobstore with path :path using the CLI
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorTriesToGetABlobWithPathUsingTheCli(string $path): void {
|
||||
$body = ["command" => "storage-users blobstore get --path=" . $path];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator gets a blob from the blobstore by ID using the CLI
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorGetsABlobFromTheBlobstoreByIdUsingTheCli(): void {
|
||||
$blobPath = $this->findNewestBlobPath();
|
||||
|
||||
// The blob path is "<root>/spaces/<pathifiedSpaceID>/blobs/<pathifiedBlobID>".
|
||||
// The raw space/blob IDs are recovered by stripping the pathify separators,
|
||||
// which is exactly what the CLI's depathify does on the way back in.
|
||||
[, $rest] = \explode('/spaces/', $blobPath, 2);
|
||||
[$pathifiedSpaceID, $pathifiedBlobID] = \explode('/blobs/', $rest, 2);
|
||||
$spaceId = \str_replace('/', '', $pathifiedSpaceID);
|
||||
$blobId = \str_replace('/', '', $pathifiedBlobID);
|
||||
|
||||
$body = [
|
||||
"command" => "storage-users blobstore get"
|
||||
. " --blob-id=" . $blobId
|
||||
. " --space-id=" . $spaceId,
|
||||
];
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
@env-config
|
||||
Feature: blobstore check and get via CLI
|
||||
As an administrator
|
||||
I want to verify blobstore connectivity
|
||||
So that I can ensure my storage backend is working correctly
|
||||
|
||||
|
||||
Scenario: administrator checks the blobstore
|
||||
When the administrator checks the blobstore using the CLI
|
||||
Then the command should be successful
|
||||
And the CLI response should contain the following message:
|
||||
"""
|
||||
Upload: OK
|
||||
Download and verify: OK
|
||||
Delete: OK
|
||||
Blobstore check successful.
|
||||
"""
|
||||
|
||||
|
||||
Scenario: administrator checks the blobstore with a valid blob size
|
||||
When the administrator checks the blobstore with blob size "1KB" using the CLI
|
||||
Then the command should be successful
|
||||
And the CLI response should contain the following message:
|
||||
"""
|
||||
Upload: OK
|
||||
Download and verify: OK
|
||||
Delete: OK
|
||||
Blobstore check successful.
|
||||
"""
|
||||
|
||||
|
||||
Scenario: administrator checks the blobstore with an invalid blob size
|
||||
When the administrator checks the blobstore with blob size "abc" using the CLI
|
||||
Then the command should be unsuccessful
|
||||
And the command output should contain "invalid --blob-size"
|
||||
|
||||
|
||||
Scenario: administrator tries to get a blob without providing required flags
|
||||
When the administrator tries to get a blob from the blobstore using the CLI
|
||||
Then the command should be unsuccessful
|
||||
And the command output should contain "either --path or both --blob-id and --space-id must be set"
|
||||
|
||||
|
||||
Scenario: administrator tries to get a non-existent blob from the blobstore
|
||||
When the administrator tries to get a non-existent blob from the blobstore using the CLI
|
||||
Then the command should be unsuccessful
|
||||
And the command output should contain "download failed: could not read blob"
|
||||
|
||||
@skipOnOcis-S3NG-Storage
|
||||
Scenario: administrator gets a blob from the blobstore using the --path flag
|
||||
Given user "Alice" has been created with default attributes
|
||||
And user "Alice" has uploaded file with content "hello world" to "/textfile0.txt"
|
||||
When the administrator gets a blob from the blobstore using the --path flag via the CLI
|
||||
Then the command should be successful
|
||||
And the command output should contain "Download: OK"
|
||||
|
||||
@skipOnOcis-S3NG-Storage
|
||||
Scenario: administrator gets a blob from the blobstore by ID
|
||||
Given user "Alice" has been created with default attributes
|
||||
And user "Alice" has uploaded file with content "hello world" to "/textfile0.txt"
|
||||
When the administrator gets a blob from the blobstore by ID using the CLI
|
||||
Then the command should be successful
|
||||
And the command output should contain "Download: OK"
|
||||
|
||||
|
||||
Scenario: administrator tries to get a blob with a malformed ocis blob path
|
||||
When the administrator tries to get a blob from the blobstore with path "/spaces/b1/9ec764-/nope" using the CLI
|
||||
Then the command should be unsuccessful
|
||||
And the command output should contain "missing /blobs/ segment"
|
||||
|
||||
|
||||
Scenario: administrator tries to get a blob with a malformed s3ng blob path
|
||||
When the administrator tries to get a blob from the blobstore with path "notas3ngpath" using the CLI
|
||||
Then the command should be unsuccessful
|
||||
And the command output should contain "expected <spaceID>/<pathified_blobID>"
|
||||
Reference in new issue
Block a user