X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=t%2Fscans.t;h=566d578d4f272de4186590bd413e9a774a3882b7;hb=07d0555058636b2b6ebb8c6bd757f9dfde072dba;hp=df404dd62030f6facb7924ff1642489f3b64d8c8;hpb=0000c72e6700ef1af5dd4ef608d6a9f00b30442d;p=ndwebbie.git diff --git a/t/scans.t b/t/scans.t index df404dd..566d578 100644 --- a/t/scans.t +++ b/t/scans.t @@ -28,15 +28,22 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) is ($fleets[0]->{ships}->[0]->{ship}, 'Centaur'); is ($fleets[0]->{ships}->[0]->{amount}, 199900); is ($fleets[0]->{amount}, 253901); + is ($fleets[0]->{mission}, 'Military'); is ($fleets[1]->{name}, 'Fleet 1'); is (scalar @{$fleets[1]->{ships}}, 1); is ($fleets[1]->{ships}->[0]->{ship}, 'Chimera'); is ($fleets[1]->{ships}->[0]->{amount}, 54500); is ($fleets[1]->{amount}, 54500); + is ($fleets[1]->{mission}, 'Military'); is ($fleets[2]->{name}, 'Fleet 2'); is ($fleets[2]->{amount}, 0); + is ($fleets[2]->{mission}, 'Military'); is ($fleets[3]->{name}, 'Fleet 3'); is ($fleets[3]->{amount}, 0); + is ($fleets[3]->{mission}, 'Military'); + is ($fleets[4]->{name}, 'Military'); + is ($fleets[4]->{mission}, 'Full fleet'); + is ($fleets[4]->{amount}, 253901+54500); } { @@ -48,16 +55,17 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) }; doMilScan($dbh, $scan, $milscan); my $history = $dbh->{mock_all_history}; - is(scalar(@{$history}), 3, 'Correct number of statements executed'); + is(scalar(@{$history}), 3, 'Add military scan'); #print Dumper($history), "\n"; { my $sth = $history->[0]; my $exec_history = $sth->{execution_history}; like($sth->statement, - qr{INSERT INTO fleets \(name, mission, pid, tick, amount\).*}sm, + qr{^INSERT INTO fleets \(name, mission, pid, tick, amount\)}ism, ); - is(scalar(@{$exec_history}), 2); + is(scalar(@{$exec_history}), 3); + is(scalar(@{$exec_history->[0]->{params}}), 5); is($exec_history->[0]->{params}->[0], "Base"); is($exec_history->[0]->{params}->[1], "Military"); is($exec_history->[0]->{params}->[2], $scan->{pid}); @@ -70,26 +78,36 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) is($exec_history->[1]->{params}->[3], $scan->{tick}); is($exec_history->[1]->{params}->[4], 54500); + is($exec_history->[2]->{params}->[0], "Military"); + is($exec_history->[2]->{params}->[1], "Full fleet"); + is($exec_history->[2]->{params}->[2], $scan->{pid}); + is($exec_history->[2]->{params}->[3], $scan->{tick}); + is($exec_history->[2]->{params}->[4], 253901+54500); + } { my $sth = $history->[1]; my $exec_history = $sth->{execution_history}; like($sth->statement, - qr{INSERT INTO fleet_scans \(fid, id\).*}sm, + qr{^INSERT INTO fleet_scans \(fid, id\)}ism, ); - is(scalar(@{$exec_history}), 2); + is(scalar(@{$exec_history}), 3); + is(scalar(@{$exec_history->[0]->{params}}), 2); is($exec_history->[0]->{params}->[0], $fid); is($exec_history->[0]->{params}->[1], $scan->{id}); is($exec_history->[1]->{params}->[0], $fid); is($exec_history->[1]->{params}->[1], $scan->{id}); + is($exec_history->[2]->{params}->[0], $fid); + is($exec_history->[2]->{params}->[1], $scan->{id}); } { my $sth = $history->[2]; my $exec_history = $sth->{execution_history}; like($sth->statement, - qr{INSERT INTO fleet_ships \(fid, ship, amount\).*}sm, + qr{^INSERT INTO fleet_ships \(fid, ship, amount\)}ism, ); - is(scalar(@{$exec_history}), 5); + is(scalar(@{$exec_history}), 10); + is(scalar(@{$exec_history->[0]->{params}}), 3); is($exec_history->[0]->{params}->[0], $fid); is($exec_history->[0]->{params}->[1], 'Centaur'); is($exec_history->[0]->{params}->[2], 199900); @@ -105,7 +123,62 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) is($exec_history->[4]->{params}->[0], $fid); is($exec_history->[4]->{params}->[1], 'Chimera'); is($exec_history->[4]->{params}->[2], 54500); + is($exec_history->[5]->{params}->[0], $fid); + is($exec_history->[5]->{params}->[1], 'Centaur'); + is($exec_history->[5]->{params}->[2], 199900); + is($exec_history->[6]->{params}->[0], $fid); + is($exec_history->[6]->{params}->[1], 'Chimera'); + is($exec_history->[6]->{params}->[2], 54500); + is($exec_history->[7]->{params}->[0], $fid); + is($exec_history->[7]->{params}->[1], 'Titan'); + is($exec_history->[7]->{params}->[2], 50000); + is($exec_history->[8]->{params}->[0], $fid); + is($exec_history->[8]->{params}->[1], 'Wyvern'); + is($exec_history->[8]->{params}->[2], 3000); + is($exec_history->[9]->{params}->[0], $fid); + is($exec_history->[9]->{params}->[1], 'Medusa'); + is($exec_history->[9]->{params}->[2], 1001); } + +} + +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();