]> ruin.nu Git - ndwebbie.git/blobdiff - t/scans.t
Make Planet Scan parsing testable
[ndwebbie.git] / t / scans.t
index df404dd62030f6facb7924ff1642489f3b64d8c8..37647d922552e3025830291d7cb754e942051a66 100644 (file)
--- a/t/scans.t
+++ b/t/scans.t
@@ -106,6 +106,46 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
                is($exec_history->[4]->{params}->[1], 'Chimera');
                is($exec_history->[4]->{params}->[2], 54500);
        }
+
+}
+
+my $planetscan = do {
+       open my $in, '<', "$FindBin::Bin/planetscan.html" or die "Can't read file: $!";
+       local $/;
+       <$in>
+};
+
+$dbh->{mock_clear_history} = 1;
+{
+       my $scan = {id => 31337, type => 'Planet', pid => 1337, tick => 123};
+       doPlanetScan($dbh, $scan, $planetscan);
+       my $history = $dbh->{mock_all_history};
+       is(scalar(@{$history}), 1, 'Add planet scan');
+
+       my $sth = $history->[0];
+       my $exec_history = $sth->{execution_history};
+       like($sth->statement,
+               qr{\QINSERT INTO planet_scans\E\s*
+                       \(id,tick,pid,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium
+                               \s*,agents,guards,light,medium,heavy,hidden\).*}xsi,
+       );
+       is(scalar(@{$exec_history}), 1);
+       is(scalar(@{$exec_history->[0]->{params}}), 15);
+       is($exec_history->[0]->{params}->[0], $scan->{id});
+       is($exec_history->[0]->{params}->[1], $scan->{tick});
+       is($exec_history->[0]->{params}->[2], $scan->{pid});
+       is($exec_history->[0]->{params}->[3], 100);
+       is($exec_history->[0]->{params}->[4], 78363);
+       is($exec_history->[0]->{params}->[5], 130);
+       is($exec_history->[0]->{params}->[6], 147874);
+       is($exec_history->[0]->{params}->[7], 100);
+       is($exec_history->[0]->{params}->[8], 169077);
+       is($exec_history->[0]->{params}->[9], 100);
+       is($exec_history->[0]->{params}->[10], 805);
+       is($exec_history->[0]->{params}->[11], 'None');
+       is($exec_history->[0]->{params}->[12], 'High');
+       is($exec_history->[0]->{params}->[13], 'None');
+       is($exec_history->[0]->{params}->[14], '4612500');
 }
 
 done_testing();