Replace TestHTTPMockServer with python script
This seems to work fine in a `nix build`-sandbox as it doesn't depend on `getprotobyname`.
This commit is contained in:
parent
d16bf5b8cd
commit
2beb1f5405
42
flake.nix
42
flake.nix
|
@ -56,41 +56,6 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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=";
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
FunctionParameters = final.buildPerlPackage {
|
FunctionParameters = final.buildPerlPackage {
|
||||||
pname = "Function-Parameters";
|
pname = "Function-Parameters";
|
||||||
version = "2.001003";
|
version = "2.001003";
|
||||||
|
@ -299,7 +264,6 @@
|
||||||
EmailSender
|
EmailSender
|
||||||
FileSlurp
|
FileSlurp
|
||||||
FileWhich
|
FileWhich
|
||||||
HTTPParser
|
|
||||||
IOCompress
|
IOCompress
|
||||||
IPCRun
|
IPCRun
|
||||||
JSON
|
JSON
|
||||||
|
@ -317,7 +281,6 @@
|
||||||
Starman
|
Starman
|
||||||
SysHostnameLong
|
SysHostnameLong
|
||||||
TermSizeAny
|
TermSizeAny
|
||||||
TestHTTPMockServer
|
|
||||||
TestMore
|
TestMore
|
||||||
TestPostgreSQL
|
TestPostgreSQL
|
||||||
TextDiff
|
TextDiff
|
||||||
|
@ -348,7 +311,7 @@
|
||||||
];
|
];
|
||||||
|
|
||||||
checkInputs = [
|
checkInputs = [
|
||||||
foreman
|
foreman python3
|
||||||
];
|
];
|
||||||
|
|
||||||
hydraPath = lib.makeBinPath (
|
hydraPath = lib.makeBinPath (
|
||||||
|
@ -382,6 +345,9 @@
|
||||||
export LOGNAME=''${LOGNAME:-foo}
|
export LOGNAME=''${LOGNAME:-foo}
|
||||||
# set $HOME for bzr so it can create its trace file
|
# set $HOME for bzr so it can create its trace file
|
||||||
export HOME=$(mktemp -d)
|
export HOME=$(mktemp -d)
|
||||||
|
|
||||||
|
export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocols
|
||||||
|
export LD_PRELOAD="${pkgs.libredirect}/lib/libredirect.so"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
|
|
35
t/jobs/server.py
Normal file
35
t/jobs/server.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
|
||||||
|
def factory(file):
|
||||||
|
h = handler
|
||||||
|
h.file = file
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
class 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) > 1
|
||||||
|
with HTTPServer(('localhost', 8282), factory(argv[1])) as server:
|
||||||
|
server.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
|
@ -4,11 +4,6 @@ use warnings;
|
||||||
use JSON;
|
use JSON;
|
||||||
use Setup;
|
use Setup;
|
||||||
|
|
||||||
use Test::HTTP::MockServer;
|
|
||||||
|
|
||||||
my $server = Test::HTTP::MockServer->new();
|
|
||||||
my $url = $server->url_base();
|
|
||||||
|
|
||||||
my %ctx = test_init(
|
my %ctx = test_init(
|
||||||
hydra_config => q|
|
hydra_config => q|
|
||||||
<gitea_authorization>
|
<gitea_authorization>
|
||||||
|
@ -40,7 +35,7 @@ sub addStringInput {
|
||||||
addStringInput($jobset, "gitea_repo_owner", "root");
|
addStringInput($jobset, "gitea_repo_owner", "root");
|
||||||
addStringInput($jobset, "gitea_repo_name", "foo");
|
addStringInput($jobset, "gitea_repo_name", "foo");
|
||||||
addStringInput($jobset, "gitea_status_repo", "src");
|
addStringInput($jobset, "gitea_status_repo", "src");
|
||||||
addStringInput($jobset, "gitea_http_url", "$url/gitea");
|
addStringInput($jobset, "gitea_http_url", "http://localhost:8282/gitea");
|
||||||
|
|
||||||
updateRepository('gitea', "$ctx{testdir}/jobs/git-update.sh", $scratch);
|
updateRepository('gitea', "$ctx{testdir}/jobs/git-update.sh", $scratch);
|
||||||
|
|
||||||
|
@ -51,24 +46,19 @@ is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand.nix should r
|
||||||
ok(runBuild($build), "Build should succeed with exit code 0");
|
ok(runBuild($build), "Build should succeed with exit code 0");
|
||||||
|
|
||||||
my $filename = $ENV{'HYDRA_DATA'} . "/giteaout.json";
|
my $filename = $ENV{'HYDRA_DATA'} . "/giteaout.json";
|
||||||
my $handle = sub {
|
my $pid;
|
||||||
my ($request, $response) = @_;
|
if (!defined($pid = fork())) {
|
||||||
|
die "Cannot fork(): $!";
|
||||||
open(FH, ">", $filename) or die("Can't open(): $!\n");
|
} elsif ($pid == 0) {
|
||||||
print FH $request->uri . "\n";
|
exec("python3 $ctx{jobsdir}/server.py $filename");
|
||||||
print FH $request->content . "\n";
|
} else {
|
||||||
close(FH);
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
};
|
|
||||||
|
|
||||||
$server->start_mock_server($handle);
|
|
||||||
my $newbuild = $db->resultset('Builds')->find($build->id);
|
my $newbuild = $db->resultset('Builds')->find($build->id);
|
||||||
is($newbuild->finished, 1, "Build should be finished.");
|
is($newbuild->finished, 1, "Build should be finished.");
|
||||||
is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");
|
is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");
|
||||||
ok(sendNotifications(), "Sent notifications");
|
ok(sendNotifications(), "Sent notifications");
|
||||||
|
|
||||||
$server->stop_mock_server();
|
kill('INT', $pid);
|
||||||
|
}
|
||||||
|
|
||||||
open my $fh, $filename or die ("Can't open(): $!\n");
|
open my $fh, $filename or die ("Can't open(): $!\n");
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
|
|
Loading…
Reference in a new issue