]> iEval git - gruntmaster-daemon.git/commitdiff
Add test for SendResults
authorandreisamoila74 <samoilaandrei76@gmail.com>
Mon, 9 Nov 2020 10:32:10 +0000 (12:32 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 17 Apr 2022 18:38:40 +0000 (21:38 +0300)
t/02-send-results-request.t [new file with mode: 0644]

diff --git a/t/02-send-results-request.t b/t/02-send-results-request.t
new file mode 100644 (file)
index 0000000..816e991
--- /dev/null
@@ -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 = <<CONF;
+log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
+
+log4perl.appender.stderr                          = Log::Log4perl::Appender::Screen
+log4perl.appender.stderr.layout                   = Log::Log4perl::Layout::PatternLayout
+log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
+CONF
+Log::Log4perl->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 = <t/problems/aplusb/tests/40>;
+  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();
This page took 0.029834 seconds and 4 git commands to generate.