From 13b428ecae5717fbcdf8b7141db62a7846636274 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 8 Jul 2024 17:35:23 +0545 Subject: [PATCH] refactor: remove stdins from the command logs --- tests/TestHelpers/CliHelper.php | 7 ++--- .../features/bootstrap/CliContext.php | 31 ++++++++++--------- .../features/bootstrap/FeatureContext.php | 1 - .../resetUserPassword.feature | 2 +- tests/ociswrapper/ocis/ocis.go | 3 ++ 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tests/TestHelpers/CliHelper.php b/tests/TestHelpers/CliHelper.php index fee84ad332..bf281b5c77 100644 --- a/tests/TestHelpers/CliHelper.php +++ b/tests/TestHelpers/CliHelper.php @@ -32,15 +32,14 @@ use TestHelpers\OcisConfigHelper; * A helper class for running oCIS CLI commands */ class CliHelper { - /** * @param array $body * * @return ResponseInterface * @throws GuzzleException */ - public static function runCommand(array $body): ResponseInterface { + public static function runCommand(array $body): ResponseInterface { $url = OcisConfigHelper::getWrapperUrl() . "/command"; return OcisConfigHelper::sendRequest($url, "POST", \json_encode($body)); - } -} \ No newline at end of file + } +} diff --git a/tests/acceptance/features/bootstrap/CliContext.php b/tests/acceptance/features/bootstrap/CliContext.php index 8a4f75bcf8..51a7c7e5af 100644 --- a/tests/acceptance/features/bootstrap/CliContext.php +++ b/tests/acceptance/features/bootstrap/CliContext.php @@ -45,7 +45,7 @@ class CliContext implements Context { $environment = $scope->getEnvironment(); // Get all the contexts you need in this context $this->featureContext = $environment->getContext('FeatureContext'); - } + } /** * @Given the administrator has stopped the server @@ -53,7 +53,7 @@ class CliContext implements Context { * @return void */ public function theAdministratorHasStoppedTheServer(): void { - $response = OcisConfigHelper::stopOcis(); + $response = OcisConfigHelper::stopOcis(); $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); } @@ -63,7 +63,7 @@ class CliContext implements Context { * @return void */ public function theAdministratorHasStartedTheServer(): void { - $response = OcisConfigHelper::startOcis(); + $response = OcisConfigHelper::startOcis(); $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); } @@ -76,13 +76,13 @@ class CliContext implements Context { * @return void */ public function theAdministratorResetsThePasswordOfUserUsingTheCLI(string $user, string $password): void { - $command = "idm resetpassword -u $user"; - $body = [ - "command" => $command, - "inputs" => [$password, $password] - ]; + $command = "idm resetpassword -u $user"; + $body = [ + "command" => $command, + "inputs" => [$password, $password] + ]; - $this->featureContext->setResponse(CliHelper::runCommand($body)); + $this->featureContext->setResponse(CliHelper::runCommand($body)); $this->featureContext->updateUserPassword($user, $password); } @@ -92,24 +92,25 @@ class CliContext implements Context { * @return void */ public function theCommandShouldBeSuccessful(): void { - $response = $this->featureContext->getResponse(); + $response = $this->featureContext->getResponse(); $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); $jsonResponse = $this->featureContext->getJsonDecodedResponse($response); - Assert::assertSame("OK", $jsonResponse["status"]); - Assert::assertSame(0, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"]); + Assert::assertSame("OK", $jsonResponse["status"]); + Assert::assertSame(0, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"]); } /** * @Then /^the command output (should|should not) contain "([^"]*)"$/ * + * @param string $shouldOrNot * @param string $output * * @return void */ - public function theCommandOutputShouldContain(string $shouldOrNot,string $output): void { - $response = $this->featureContext->getResponse(); + public function theCommandOutputShouldContain(string $shouldOrNot, string $output): void { + $response = $this->featureContext->getResponse(); $jsonResponse = $this->featureContext->getJsonDecodedResponse($response); if ($shouldOrNot === "should") { @@ -118,4 +119,4 @@ class CliContext implements Context { Assert::assertStringNotContainsString($output, $jsonResponse["message"]); } } -} \ No newline at end of file +} diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index e2ea3a12c1..c85700f271 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -672,7 +672,6 @@ class FeatureContext extends BehatVariablesContext { $this->theHTTPStatusCodeShouldBe([200, 409], 'Starting oCIS server', $response); } - /** * Get the externally-defined admin username, if any * diff --git a/tests/acceptance/features/cliResetPassword/resetUserPassword.feature b/tests/acceptance/features/cliResetPassword/resetUserPassword.feature index a0a314652f..c5a015c9d9 100644 --- a/tests/acceptance/features/cliResetPassword/resetUserPassword.feature +++ b/tests/acceptance/features/cliResetPassword/resetUserPassword.feature @@ -14,4 +14,4 @@ Feature: reset user password via CLI command But the command output should not contain "Failed to update user password: entry does not exist" And the administrator has started the server And user "Alice" should be able to create folder "newFolder" using password "newpass" - But user "Alice" should not be able to create folder "anotherFolder" using password "%alt1%" \ No newline at end of file + But user "Alice" should not be able to create folder "anotherFolder" using password "%alt1%" diff --git a/tests/ociswrapper/ocis/ocis.go b/tests/ociswrapper/ocis/ocis.go index ca8befa1da..aa4a69dd99 100644 --- a/tests/ociswrapper/ocis/ocis.go +++ b/tests/ociswrapper/ocis/ocis.go @@ -266,5 +266,8 @@ func RunCommand(command string, inputs []string) (int, string) { io.Copy(logs, ptyF) cmdOutput += logs.String() + // TODO: find if there is a better way to remove stdins from the output + cmdOutput = strings.TrimLeft(cmdOutput, strings.Join(inputs, "\r\n")) + return c.ProcessState.ExitCode(), cmdOutput }