1
0

finished selftest module

This commit is contained in:
Mike Schwörer 2020-01-20 17:42:52 +01:00
parent 63b43e882c
commit cb71f40250
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 33 additions and 19 deletions

View File

@ -14,20 +14,21 @@ class SelfTest implements IWebsiteModule
'web::blog' => 'Blog (http)', 'web::blog' => 'Blog (http)',
'web::webapps' => 'WebApps (http)', 'web::webapps' => 'WebApps (http)',
'web::euler' => 'Project Euler (http)', 'web::euler' => 'Project Euler (http)',
'web::aoc' => 'Advent of code (http)', 'web::aoc' => 'Advent of Code (http)',
'api::default' => 'API', 'api::default' => 'API',
'api::highscore' => 'Highscores API', 'api::highscore' => 'Highscores API',
'modules::database' => 'Database', 'modules::database' => 'Database',
'modules::blog' => 'blog', 'modules::blog' => 'Blog (data)',
'modules::euler' => 'Project Euler', 'modules::euler' => 'Project Euler (data)',
'modules::books' => 'Books', 'modules::books' => 'Books (data)',
'modules::extgitgraph' => 'ExtendedGitGraph', 'modules::extgitgraph' => 'ExtendedGitGraph (data)',
'modules::programs' => 'Programs', 'modules::programs' => 'Programs (data)',
'modules::adventofcode' => 'Advent of Code', 'modules::adventofcode' => 'Advent of Code (data)',
'modules::anstatistics' => 'AlephNote Stats', 'modules::anstatistics' => 'AlephNote Stats (data)',
'modules::updateslog' => 'Program Updates', 'modules::updateslog' => 'Program Updates (data)',
'modules::webapps' => 'Webapps', 'modules::webapps' => 'Webapps (data)',
'modules::highscores' => 'Highscores', 'modules::highscores' => 'Highscores (data)',
'backend::git' => 'Git Repository'
]; ];
private $methods = []; private $methods = [];
@ -164,6 +165,9 @@ class SelfTest implements IWebsiteModule
'base' => $d 'base' => $d
]; ];
} }
sort($result);
return $result; return $result;
} }
@ -199,7 +203,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong statuscode', 'message' => '{'.$xname.'} failed: Request returned wrong statuscode',
'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'], 'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }
@ -250,7 +254,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong statuscode', 'message' => '{'.$xname.'} failed: Request returned wrong statuscode',
'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'], 'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }
@ -357,7 +361,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong statuscode', 'message' => '{'.$xname.'} failed: Request returned wrong statuscode',
'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'], 'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }
@ -367,7 +371,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong statuscode', 'message' => '{'.$xname.'} failed: Request returned wrong statuscode',
'long' => "Wrong HTTP Response\nExpected:\n$json_expected\nFound:\n".$r['output'] . "\n" . "HTTP Statuscode:\n" . $r['statuscode'], 'long' => "Wrong HTTP Response\nExpected:\n$json_expected\nFound:\n".$r['output'] . "\n" . "HTTP Statuscode:\n" . $r['statuscode'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }
@ -460,6 +464,14 @@ class SelfTest implements IWebsiteModule
{ {
$xname = explode('::', $name)[2]; $xname = explode('::', $name)[2];
if (!Website::inst()->isProd()) return
[
'result' => self::STATUS_WARN,
'message' => '{'.$xname.'} not executed: curl requests in dev mode prohibited',
'long' => null,
'exception' => null,
];
try try
{ {
$message = ''; $message = '';
@ -479,7 +491,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '['.$prog['name'].'] failed: Request to returned wrong statuscode', 'message' => '['.$prog['name'].'] failed: Request to returned wrong statuscode',
'long' => 'Wrong HTTP Statuscode from "'.$url.'"' . "\nExpected: [200]\nFound: [".$r['statuscode'].']' . "\n" . "Response:\n" . $r['output'], 'long' => 'Wrong HTTP Statuscode from "'.$url.'"' . "\nExpected: [200]\nFound: [".$r['statuscode'].']' . "\n" . "Response:\n" . $r['output'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }
@ -539,7 +551,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong statuscode', 'message' => '{'.$xname.'} failed: Request returned wrong statuscode',
'long' => 'Wrong HTTP Statuscode (Expected: [200]; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'] . "\n" . "Redirect:\n" . $r['redirect'], 'long' => 'Wrong HTTP Statuscode (Expected: [200]; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'] . "\n" . "Redirect:\n" . $r['redirect'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }
@ -549,7 +561,7 @@ class SelfTest implements IWebsiteModule
[ [
'result' => self::STATUS_ERROR, 'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong redirect', 'message' => '{'.$xname.'} failed: Request returned wrong redirect',
'long' => 'Wrong Redirect URL (Expected: ['.$url2.']; Found: ['.$r['redirect'].'])' . "\n" . "Response:\n" . $r['output'] . "\n" . "Redirect:\n" . $r['redirect'], 'long' => 'Wrong Redirect URL (Expected: ['.$url2.']; Found: ['.$r['redirect'].'])' . "\n" . "Response:\n" . $r['output'] . "\n" . "Redirect:\n" . $r['redirect'] . "\nError [" . $r['errnum'] . "]:\n" . $r['errstr'],
'exception' => null, 'exception' => null,
]; ];
} }

View File

@ -277,9 +277,11 @@ function curl_http_request($url)
$output = curl_exec($ch); $output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL); $redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
$errnum = curl_errno( $ch );
$errmsg = curl_error( $ch );
curl_close($ch); curl_close($ch);
return [ 'output'=>$output, 'statuscode'=>$httpcode, 'redirect'=>$redirect ]; return [ 'output'=>$output, 'statuscode'=>$httpcode, 'redirect'=>$redirect, 'erronum'=>$errnum, 'errorstr'=>$errmsg ];
} }