From 735b24fff59f0b3960c72f6a10824b4134425b67 Mon Sep 17 00:00:00 2001 From: Niraj Acharya Date: Wed, 10 Jul 2024 14:31:37 +0545 Subject: [PATCH] adding test for backup consistency cli command --- tests/acceptance/config/behat.yml | 2 ++ .../features/bootstrap/CliContext.php | 15 +++++++++++ .../features/bootstrap/FeatureContext.php | 16 ++++++++++++ .../cliCommands/backupConsistency.feature | 26 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 tests/acceptance/features/cliCommands/backupConsistency.feature diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 348dce25cca..cb965fe6cab 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -397,6 +397,8 @@ default: contexts: - FeatureContext: *common_feature_context_params - CliContext: + - OcisConfigContext: + - SharingNgContext: extensions: rdx\behatvars\BehatVariablesExtension: ~ diff --git a/tests/acceptance/features/bootstrap/CliContext.php b/tests/acceptance/features/bootstrap/CliContext.php index 51a7c7e5af5..5067948641c 100644 --- a/tests/acceptance/features/bootstrap/CliContext.php +++ b/tests/acceptance/features/bootstrap/CliContext.php @@ -86,6 +86,20 @@ public function theAdministratorResetsThePasswordOfUserUsingTheCLI(string $user, $this->featureContext->updateUserPassword($user, $password); } + /** + * @When the administrator checks the backup consistency using the CLI + * + * @return void + */ + public function theAdministratorChecksTheBackupConsistencyUsingTheCli():void { + $path = $this->featureContext->getStorageUsersRoot(); + $command = "backup consistency -p $path"; + $body = [ + "command" => $command + ]; + $this->featureContext->setResponse(CliHelper::runCommand($body)); + } + /** * @Then the command should be successful * @@ -112,6 +126,7 @@ public function theCommandShouldBeSuccessful(): void { public function theCommandOutputShouldContain(string $shouldOrNot, string $output): void { $response = $this->featureContext->getResponse(); $jsonResponse = $this->featureContext->getJsonDecodedResponse($response); + $output = $this->featureContext->substituteInLineCodes($output); if ($shouldOrNot === "should") { Assert::assertStringContainsString($output, $jsonResponse["message"]); diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 28ecac30815..e1fcbb8c132 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -794,6 +794,14 @@ public function getBaseUrl(): string { return $this->baseUrl; } + /** + * @return string + */ + public function getStorageUsersRoot(): string { + $ocisDataPath = getenv("OCIS_BASE_DATA_PATH") ? getenv("OCIS_BASE_DATA_PATH") : getenv("HOME") . '/.ocis'; + return getenv("STORAGE_USERS_OCIS_ROOT") ? getenv("STORAGE_USERS_OCIS_ROOT") : $ocisDataPath . "/storage/users"; + } + /** * returns the path of the base URL * e.g. owncloud-core/10 if the baseUrl is http://localhost/owncloud-core/10 @@ -2072,6 +2080,14 @@ public function substituteInLineCodes( ], "parameter" => [] ], + [ + "code" => "%storage_path%", + "function" => [ + $this, + "getStorageUsersRoot" + ], + "parameter" => [] + ], [ "code" => "%base_url_without_scheme%", "function" => [ diff --git a/tests/acceptance/features/cliCommands/backupConsistency.feature b/tests/acceptance/features/cliCommands/backupConsistency.feature new file mode 100644 index 00000000000..5f1e6d6fd95 --- /dev/null +++ b/tests/acceptance/features/cliCommands/backupConsistency.feature @@ -0,0 +1,26 @@ +@env-config +Feature: backup consistency + As a user + I want to check my data for inconsistencies + So that I can backup my data + + + Scenario: check backup consistency via CLI command + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + | Carol | + And user "Alice" has created folder "/uploadFolder" + And user "Carol" has created folder "/uploadFolder" + And user "Alice" has sent the following resource share invitation: + | resource | uploadFolder | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Editor | + And user "Carol" has deleted file "/uploadFolder" + And the administrator has stopped the server + When the administrator checks the backup consistency using the CLI + Then the command should be successful + And the command output should contain "💚 No inconsistency found. The backup in '%storage_path%' seems to be valid." \ No newline at end of file