From: andreisamoila74 Date: Mon, 9 Nov 2020 10:32:10 +0000 (+0200) Subject: Add test for SendResults X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=8d32c68b6a3511ebfb5bb3b2be518988d3900065;p=gruntmaster-daemon.git Add test for SendResults --- diff --git a/t/02-send-results-request.t b/t/02-send-results-request.t new file mode 100644 index 0000000..816e991 --- /dev/null +++ b/t/02-send-results-request.t @@ -0,0 +1,68 @@ +#!/usr/bin/perl -w +use v5.14; +use strict; +use warnings; + +use Gruntmaster::Daemon qw/process/; + +use Cwd qw/getcwd/; +use File::Slurp qw/read_file/; +use File::Temp qw/tempdir/; +use HTTP::Tiny; +use Hash::Merge qw/merge/; +use JSON qw/encode_json decode_json/; +use Log::Log4perl; +use Test::HTTP::LocalServer; +use Test::More; +use YAML::Tiny qw/LoadFile/; + +my $server = Test::HTTP::LocalServer->spawn; +my $response = HTTP::Tiny->new->get( $server->url ); +$ENV{REMOTE_ADDRESS} = $server->url; + +my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF'); +my $log_conf = <init(\$log_conf); + +my $tempdir = tempdir "gruntmasterd-testingXXXX", TMPDIR => 1, CLEANUP => 1; +chmod 0777, $tempdir; + +sub process_meta() { + my $pbmeta = LoadFile "t/problems/aplusb/meta.yml"; + for (1 .. $pbmeta->{testcnt}) { + $pbmeta->{infile}[$_ - 1] = read_file "t/problems/aplusb/$_.in" + if $pbmeta->{generator} eq 'File'; + $pbmeta->{okfile}[$_ - 1] = read_file "t/problems/aplusb/$_.ok" + if $pbmeta->{runner} && $pbmeta->{runner} eq 'File'; + } + my $source = ; + my $meta = LoadFile "$source/meta.yml"; + $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}"; + $meta = merge $meta, $pbmeta; + my $savedcwd = getcwd; + chdir $tempdir; + $meta->{job_id} = 1; + Gruntmaster::Daemon::process($meta); + chdir $savedcwd; +} + +sub send_request() { + process_meta(); + + my $requests = $server->get_log; + is $requests =~ qr/"result_text":"40 points"/, 1; + is $requests =~ qr/"result":10/, 1; + is $requests =~ qr/"gm_id":1/, 1; +} + +send_request(); + +$server->stop; + +done_testing();