Skip to content

Commit

Permalink
more & better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarin committed Sep 5, 2024
1 parent 65d376f commit 5e1a786
Showing 1 changed file with 69 additions and 15 deletions.
84 changes: 69 additions & 15 deletions t/enqueue.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe "bin/enqueue.pl" => sub {

return HTFeed::Queue->new->enqueue(%params);
}

sub get_vol_from_queue {
my $volume = shift || testvolume;
my $status = shift || "ready";
Expand Down Expand Up @@ -76,42 +76,61 @@ describe "bin/enqueue.pl" => sub {
my $expect_match_count = shift;

my $full_cmd = "perl bin/enqueue.pl $cmd";
print "Check command [$full_cmd] against output [$match_rx]\n";
my (undef, undef, $line) = caller;
print "Check output from command on line $line [$full_cmd] against rx [$match_rx]\n";

# Run command, capture output.
# Use double spaces to make it look good.
my @cmd_output = `$full_cmd`;
print "Output:[\n " . join(" ", @cmd_output) . "]\n";
my $double_space = " ";
print "Output:[\n$double_space" . join($double_space, @cmd_output) . "]\n";

# Check that the desired regex was found in the output
my $match_count = grep {$_ =~ $match_rx} @cmd_output;
print "Expected match count: $expect_match_count, got $match_count\n";
print "Expected $match_rx match count: $expect_match_count, got $match_count\n";
ok($match_count == $expect_match_count);
print "\n";
}

before each => sub {
HTFeed::Bunnies->new()->reset_queue;
get_dbh()->do("DELETE FROM feed_queue");
get_dbh()->do("DELETE FROM feed_zephir_items");
get_dbh()->do("DELETE FROM feed_queue_disallow");
};

it "complains if it cannot find a matching file" => sub {
it "won't queue if missing bib data" => sub {
enqueue(
'-v -1 simple test test',
'-v -i -1 simple test test',
qr/Missing bibliographic data/,
1
);
};

it "won't reset a punted volume unless told to" => sub {
fake_bibdata(testvolume);
enqueue_testvolume(status => 'punted');

it "can queue if there is bib data" => sub {
fake_bibdata(testvolume);
enqueue(
'-v -i -1 simple test test',
qr/simple test test: queued/,
1
);
};
it "won't queue an item already in the queue using -i" => sub {
fake_bibdata(testvolume);
my $same_command = '-v -i -1 simple test test';
enqueue(
$same_command,
qr/simple test test: queued/,
1
);
enqueue(
'-v -1 simple test test',
qr/Duplicate entry 'test-test'/,
$same_command,
qr/simple test test: failure or skipped/,
1
);
};
it "needs -r or -R to queue an item already in the queue" => sub {
fake_bibdata(testvolume);
enqueue_testvolume(status => 'punted');

# Need to specify -r or -R for it to work
enqueue(
'-v -r -1 simple test test',
Expand All @@ -125,7 +144,42 @@ describe "bin/enqueue.pl" => sub {
);
};

it "" => sub {
it "uses -u to reuse punted items rather than re-download" => sub {
fake_bibdata(testvolume);
enqueue_testvolume(status => 'punted');

# -u to reuse a punted item,
# only works in combination with a reset flag (-r/-R).
# (in this case i'm also re-routing stderr to devnull,
# because i'm doing such a bad thing that enqueue.pl
# is going to print its whole pod2usage to stderr, and I don't want it)
enqueue(
'-v -u -1 simple test test 2>/dev/null',
qr/empty result/,
0
);

# This time with both -r and -u,
# but since things haven't run normally
# it won't find anything in the failed location
enqueue(
'-v -r -u -1 simple test test',
qr/can't find sip in ingest or failure location/,
1
);

# Make the failed location and put a volume there,
# and this time the punted item will be reused.
system("mkdir -p /tmp/prep/failed/test/");
system("cp /usr/local/feed/t/fixtures/volumes/test.zip /tmp/prep/failed/test/");
enqueue(
'-v -r -u -1 simple test test',
qr/punted item reused/,
1
);

# clean up
system("rm -f /tmp/prep/toingest/test/test.zip /tmp/prep/failed/test/test.zip");
};
it "" => sub {
};
Expand Down

0 comments on commit 5e1a786

Please sign in to comment.