Replace TestHTTPMockServer with python script
[?]
Apr 2, 2021, 11:07 PM
ZQLF4QLVKPCYHPJYAHKGCDTJ4CTE3UR5FLMIJ5LA76JIIFEVQAEACDependencies
- [2]
J52POHVCUpdate to NixOS 20.09 - [3]
T3HCJYPLImplement `yath`-test for the new Gitea plugin - [4]
KPWMZFHZAdd runHydra shell - [5]
LYO7KK3JAddress PR comments: - [6]
RWNXH3H2lastModified -> lastModifiedDate - [7]
2G37UFZFflake: add TestPostgreSQL for per-test DBs - [8]
IH26BRUJRun tests with yath - [9]
YBT5G74QLDAP: add the required packages to the perlPackage via the overlay - [*]
2JJP7673tests: move to t, allow `yath test` from root
Change contents
- edit in flake.nix at line 56[4.879]→[4.879:907](∅→∅),[4.907]→[3.0:338](∅→∅),[3.338]→[4.907:908](∅→∅),[4.907]→[4.907:908](∅→∅),[4.908]→[3.339:1044](∅→∅)
};};HTTPParser = final.perlPackages.buildPerlPackage {pname = "HTTP-Parser";version = "0.06";src = final.fetchurl {url = "mirror://cpan/authors/id/E/ED/EDECA/HTTP-Parser-0.06.tar.gz";sha256 = "sha256-+MWh4cvY8ndb09HOX6zIQx8FkQi/V1oMjb2kMuXAvEU=";};buildInputs = with final.perlPackages; [ TestMore URI HTTPMessage ];meta = {homepage = https://metacpan.org/pod/HTTP::Parser;description = "HTTP::Parser - parse HTTP/1.1 request into HTTP::Request/Response object";license = final.lib.licenses.artistic1;};};TestHTTPMockServer = final.perlPackages.buildPerlModule {pname = "Test-HTTP-MockServer";version = "0.0.1";src = final.fetchurl {url = "mirror://cpan/authors/id/D/DR/DRUOSO/Test-HTTP-MockServer-v0.0.1.tar.gz";sha256 = "sha256-cnVjaKGgOxA0IcJiuzk/a2nxQGbhKD3vpaLFWIqINDg="; - edit in flake.nix at line 57
buildInputs = with final.perlPackages; [ JSONXS LWP HTTPMessage HTTPParser ];doCheck = false;meta = {homepage = https://metacpan.org/pod/Test::HTTP::MockServer;description = "Implement a mock HTTP server for use in tests";license = final.lib.licenses.asl20;}; - edit in flake.nix at line 267
HTTPParser - edit in flake.nix at line 284
TestHTTPMockServer - replacement in flake.nix at line 314
foremanforeman python3 - edit in flake.nix at line 348
export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocolsexport LD_PRELOAD="${pkgs.libredirect}/lib/libredirect.so" - file addition: server.py[11.1263]
#!/usr/bin/env python3from http.server import BaseHTTPRequestHandler, HTTPServerfrom sys import argvdef factory(file):h = handlerh.file = filereturn hclass handler(BaseHTTPRequestHandler):def do_POST(self):self.send_response(200)self.send_header('Content-type', 'application/json')with open(self.file, 'w+') as f:f.write(f"{self.path}\n")length = int(self.headers.get('content-length', 0))body = str(self.rfile.read(length).decode("utf-8"))f.write(f"{body}")self.end_headers()message = "{}"self.wfile.write(bytes(message, "utf8"))if __name__ == '__main__':try:assert len(argv) > 1with HTTPServer(('localhost', 8282), factory(argv[1])) as server:server.serve_forever()except KeyboardInterrupt:pass - edit in t/plugins/gitea.t at line 6
use Test::HTTP::MockServer; - edit in t/plugins/gitea.t at line 7
my $server = Test::HTTP::MockServer->new();my $url = $server->url_base(); - replacement in t/plugins/gitea.t at line 38
addStringInput($jobset, "gitea_http_url", "$url/gitea");addStringInput($jobset, "gitea_http_url", "http://localhost:8282/gitea"); - replacement in t/plugins/gitea.t at line 49
my $handle = sub {my ($request, $response) = @_;open(FH, ">", $filename) or die("Can't open(): $!\n");print FH $request->uri . "\n";print FH $request->content . "\n";close(FH);return $response;};$server->start_mock_server($handle);my $newbuild = $db->resultset('Builds')->find($build->id);is($newbuild->finished, 1, "Build should be finished.");is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");ok(sendNotifications(), "Sent notifications");my $pid;if (!defined($pid = fork())) {die "Cannot fork(): $!";} elsif ($pid == 0) {exec("python3 $ctx{jobsdir}/server.py $filename");} else {my $newbuild = $db->resultset('Builds')->find($build->id);is($newbuild->finished, 1, "Build should be finished.");is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");ok(sendNotifications(), "Sent notifications"); - replacement in t/plugins/gitea.t at line 60
$server->stop_mock_server();kill('INT', $pid);}