Skip to content

Commit

Permalink
Merge pull request #5777 from owncloud/forward-port-remove-isTestingO…
Browse files Browse the repository at this point in the history
…nOcisOrReva

[full-ci] [tests-only] Remove `isTestingOnOcisOrReva`
  • Loading branch information
grgprarup authored Mar 9, 2023
2 parents 249adc7 + 65d11ef commit 7177c41
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 1,201 deletions.
9 changes: 3 additions & 6 deletions tests/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ public static function setOCSelectorCookie(string $oCSelectorCookie): void {
* @return int
*/
public static function numRetriesOnHttpTooEarly():int {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently reva and oCIS may return HTTP_TOO_EARLY
// So try up to 10 times before giving up.
return 10;
}
return 0;
// Currently reva and oCIS may return HTTP_TOO_EARLY
// So try up to 10 times before giving up.
return 10;
}

/**
Expand Down
247 changes: 20 additions & 227 deletions tests/TestHelpers/LoggingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,8 @@ class LoggingHelper {
public static function getLogFilePath(
?string $xRequestId = ''
):string {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we don't interact with the log file on reva or OCIS
return "";
}
$result = SetupHelper::runOcc(
['log:owncloud'],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not get owncloud log file information" .
$result ["stdOut"] . " " . $result ["stdErr"]
);
}
\preg_match(
"/Log backend ownCloud: (\w+)\sLog file: (.*)/",
$result ['stdOut'],
$matches
);
if (!isset($matches[1]) || $matches[1] !== "enabled") {
throw new Exception("log backend is not set to 'owncloud'");
}
if (!isset($matches[2])) {
throw new Exception("could not get owncloud log file information");
}
return $matches[2];
// Currently we don't interact with the log file on reva or OCIS
return "";
}

/**
Expand Down Expand Up @@ -132,23 +108,7 @@ public static function getLogFileContent(
public static function getLogLevel(
?string $xRequestId = ''
):string {
if (OcisHelper::isTestingOnOcisOrReva()) {
return "debug";
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not get log level " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
if (!\preg_match("/Log level:\s(\w+)\s\(/", $result["stdOut"], $matches)) {
throw new Exception("could not get log level");
}
return \strtolower($matches[1]);
return "debug";
}

/**
Expand All @@ -163,23 +123,8 @@ public static function setLogLevel(
?string $logLevel,
?string $xRequestId = ''
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we can't manage log file settings on reva or OCIS
return;
}
if (!\in_array($logLevel, self::LOG_LEVEL_ARRAY)) {
throw new InvalidArgumentException("invalid log level");
}
$result = SetupHelper::runOcc(
["log:manage", "--level=$logLevel"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not set log level " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
// Currently we can't manage log file settings on reva or OCIS
return;
}

/**
Expand All @@ -193,28 +138,7 @@ public static function setLogLevel(
public static function getLogBackend(
?string $xRequestId = ''
):string {
if (OcisHelper::isTestingOnOcisOrReva()) {
return "errorlog";
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not get log backend " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
$pregResult = \preg_match(
"/Enabled logging backend:\s(\w+)\n/",
$result ["stdOut"],
$matches
);
if (!$pregResult) {
throw new Exception("could not get log backend");
}
return \strtolower($matches[1]);
return "errorlog";
}

/**
Expand All @@ -232,20 +156,8 @@ public static function setLogBackend(
if (!\in_array($backend, ["owncloud", "syslog", "errorlog"])) {
throw new InvalidArgumentException("invalid log backend");
}
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we can't manage log file settings on reva or OCIS
return;
}
$result = SetupHelper::runOcc(
["log:manage", "--backend=$backend"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not set log backend " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
// Currently we can't manage log file settings on reva or OCIS
return;
}

/**
Expand All @@ -259,28 +171,7 @@ public static function setLogBackend(
public static function getLogTimezone(
?string $xRequestId = ''
):string {
if (OcisHelper::isTestingOnOcisOrReva()) {
return "UTC";
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not get log timezone " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
$pregResult = \preg_match(
"/Log timezone:\s(\w+)/",
$result ["stdOut"],
$matches
);
if (!$pregResult) {
throw new Exception("could not get log timezone");
}
return $matches[1];
return "UTC";
}

/**
Expand All @@ -295,20 +186,8 @@ public static function setLogTimezone(
?string $timezone,
?string $xRequestId = ''
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we can't manage log file settings on reva or OCIS
return;
}
$result = SetupHelper::runOcc(
["log:manage", "--timezone=$timezone"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not set log timezone " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
// Currently we can't manage log file settings on reva or OCIS
return;
}

/**
Expand All @@ -327,21 +206,8 @@ public static function clearLogFile(
?string $adminPassword,
?string $xRequestId = ''
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we don't interact with the log file on reva or OCIS
return;
}
$result = OcsApiHelper::sendRequest(
$baseUrl,
$adminUsername,
$adminPassword,
"DELETE",
"/apps/testing/api/v1/logfile",
$xRequestId
);
if ($result->getStatusCode() !== 200) {
throw new Exception("could not clear logfile");
}
// Currently we don't interact with the log file on reva or OCIS
return;
}

/**
Expand All @@ -360,41 +226,8 @@ public static function restoreLoggingStatus(
?string $timezone,
?string $xRequestId = ''
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we don't interact with the log file on reva or OCIS
return;
}
if (!\in_array(\strtolower($logLevel), self::LOG_LEVEL_ARRAY)) {
throw new InvalidArgumentException("invalid log level");
}
if (!\in_array(\strtolower($backend), ["owncloud", "syslog", "errorlog"])) {
throw new InvalidArgumentException("invalid log backend");
}

$commands = ["log:manage"];

if ($timezone) {
\array_push($commands, "--timezone=$timezone");
}
if ($logLevel) {
\array_push($commands, "--backend=$backend");
}
if ($backend) {
\array_push($commands, "--level=$logLevel");
}

if (\count($commands) > 1) {
$result = SetupHelper::runOcc(
$commands,
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not restore log status " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}
}
// Currently we don't interact with the log file on reva or OCIS
return;
}

/**
Expand All @@ -408,50 +241,10 @@ public static function restoreLoggingStatus(
public static function getLogInfo(
?string $xRequestId = ''
):array {
if (OcisHelper::isTestingOnOcisOrReva()) {
return [
"level" => "debug",
"backend" => "errorlog",
"timezone" => "UTC"
];
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
if ($result["code"] != 0) {
throw new Exception(
"could not get log level " . $result ["stdOut"] . " " .
$result ["stdErr"]
);
}

$logging = [];
if (!\preg_match("/Log level:\s(\w+)\s\(/", $result["stdOut"], $matches)) {
throw new Exception("could not get log level");
}
$logging["level"] = $matches[1];

$pregResult = \preg_match(
"/Log timezone:\s(\w+)/",
$result ["stdOut"],
$matches
);
if (!$pregResult) {
throw new Exception("could not get log timezone");
}
$logging["timezone"] = $matches[1];

$pregResult = \preg_match(
"/Enabled logging backend:\s(\w+)\n/",
$result ["stdOut"],
$matches
);
if (!$pregResult) {
throw new Exception("could not get log backend");
}
$logging["backend"] = $matches[1];

return $logging;
return [
"level" => "debug",
"backend" => "errorlog",
"timezone" => "UTC"
];
}
}
11 changes: 2 additions & 9 deletions tests/TestHelpers/OcisHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,11 @@ public static function isTestingOnReva():bool {
return (\getenv("TEST_REVA") === "true");
}

/**
* @return bool
*/
public static function isTestingOnOcisOrReva():bool {
return (self::isTestingOnOcis() || self::isTestingOnReva());
}

/**
* @return bool
*/
public static function isTestingOnOc10():bool {
return (!self::isTestingOnOcisOrReva());
return false;
}

/**
Expand Down Expand Up @@ -307,7 +300,7 @@ public static function getBindPassword():string {
*/
private static function getOcisRevaDataRoot():string {
$root = \getenv("OCIS_REVA_DATA_ROOT");
if (($root === false || $root === "") && self::isTestingOnOcisOrReva()) {
if ($root === false || $root === "") {
$root = "/var/tmp/ocis/owncloud/";
}
if (!\file_exists($root)) {
Expand Down
Loading

0 comments on commit 7177c41

Please sign in to comment.