Replace TestHTTPMockServer with python script

[?]
Apr 2, 2021, 11:07 PM
ZQLF4QLVKPCYHPJYAHKGCDTJ4CTE3UR5FLMIJ5LA76JIIFEVQAEAC

Dependencies

  • [2] J52POHVC Update to NixOS 20.09
  • [3] T3HCJYPL Implement `yath`-test for the new Gitea plugin
  • [4] KPWMZFHZ Add runHydra shell
  • [5] LYO7KK3J Address PR comments:
  • [6] RWNXH3H2 lastModified -> lastModifiedDate
  • [7] 2G37UFZF flake: add TestPostgreSQL for per-test DBs
  • [8] IH26BRUJ Run tests with yath
  • [9] YBT5G74Q LDAP: add the required packages to the perlPackage via the overlay
  • [*] 2JJP7673 tests: 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
    [3.1059][3.1059:1417]()
    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
    [4.26][3.1432:1459]()
    HTTPParser
  • edit in flake.nix at line 284
    [4.2683][3.1460:1495]()
    TestHTTPMockServer
  • replacement in flake.nix at line 314
    [4.250][4.204:224]()
    foreman
    [4.250]
    [4.275]
    foreman python3
  • edit in flake.nix at line 348
    [2.537]
    [4.4329]
    export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocols
    export LD_PRELOAD="${pkgs.libredirect}/lib/libredirect.so"
  • file addition: server.py (----------)
    [11.1263]
    #!/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
  • edit in t/plugins/gitea.t at line 6
    [3.1576][3.1576:1605]()
    use Test::HTTP::MockServer;
  • edit in t/plugins/gitea.t at line 7
    [3.1606][3.1606:1682]()
    my $server = Test::HTTP::MockServer->new();
    my $url = $server->url_base();
  • replacement in t/plugins/gitea.t at line 38
    [3.2515][3.2515:2572]()
    addStringInput($jobset, "gitea_http_url", "$url/gitea");
    [3.2515]
    [3.2572]
    addStringInput($jobset, "gitea_http_url", "http://localhost:8282/gitea");
  • replacement in t/plugins/gitea.t at line 49
    [3.2970][3.2970:3467]()
    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");
    [3.2970]
    [3.3467]
    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
    [3.3468][3.3468:3497]()
    $server->stop_mock_server();
    [3.3468]
    [3.3497]
    kill('INT', $pid);
    }