test: prepare cli test suite

This commit is contained in:
Saw-jan
2024-07-08 17:21:53 +05:45
parent 9baecdfd58
commit fd6e773b7e
3 changed files with 82 additions and 2 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php declare(strict_types=1);
/**
* ownCloud
*
* @author Sajan Gurung <sajan@jankaritech.com>
* @copyright Copyright (c) 2024 Sajan Gurung sajan@jankaritech.com
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace TestHelpers;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\ResponseInterface;
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 {
$url = OcisConfigHelper::getWrapperUrl() . "/command";
return OcisConfigHelper::sendRequest($url, "POST", \json_encode($body));
}
}
+28 -2
View File
@@ -40,7 +40,7 @@ class OcisConfigHelper {
* @return ResponseInterface
* @throws GuzzleException
*/
private static function sendRequest(
public static function sendRequest(
string $url,
string $method,
?string $body = ""
@@ -54,10 +54,18 @@ class OcisConfigHelper {
);
try {
return $client->send($request);
$response = $client->send($request);
} catch (ConnectException $e) {
throw new \Error("Cannot connect to the ociswrapper at the moment, make sure that ociswrapper is running before proceeding with the test run.\n" . $e->getMessage());
} catch (GuzzleException $ex) {
$response = $ex->getResponse();
if ($response === null) {
throw $ex;
}
}
return $response;
}
/**
@@ -90,4 +98,22 @@ class OcisConfigHelper {
$url = self::getWrapperUrl() . "/rollback";
return self::sendRequest($url, "DELETE");
}
/**
* @return ResponseInterface
* @throws GuzzleException
*/
public static function stopOcis(): ResponseInterface {
$url = self::getWrapperUrl() . "/stop";
return self::sendRequest($url, "POST");
}
/**
* @return ResponseInterface
* @throws GuzzleException
*/
public static function startOcis(): ResponseInterface {
$url = self::getWrapperUrl() . "/start";
return self::sendRequest($url, "POST");
}
}
+8
View File
@@ -368,6 +368,14 @@ default:
- SharingNgContext:
- SpacesContext:
cliResetPassword:
paths:
- "%paths.base%/../features/cliResetPassword"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- CliContext:
extensions:
rdx\behatvars\BehatVariablesExtension: ~