1 use Test::More tests => 31;
11 use_ok 'Fumo::Queue::Run';
15 skip('FUMO_TEST_DSN environment variable not set', 17)
16 unless $ENV{FUMO_TEST_DSN};
18 # just bail if we can't connect
19 my $dbh = DBI->connect($ENV{FUMO_TEST_DSN})
20 or BAIL_OUT(DBI->errstr);
22 # create the high level queue
23 my $queue = Fumo::Queue->new($dbh);
24 isa_ok($queue, 'Fumo::Queue');
27 lives_ok { $queue->empty() } 'Delete all runs from the queue';
28 cmp_ok $queue->count(), '==', 0, 'Queue count is 0';
31 my $run = Fumo::Queue::Run->new({
32 project => 'Project1',
34 revision => 'Revision1'
36 isa_ok($run, 'Fumo::Queue::Run');
39 lives_ok { $queue->put_run($run) } 'Adding new run to queue';
41 # so now there should be one run
42 cmp_ok $queue->count(), '==', 1, 'Queue count is 1';
46 # try and get it back again
47 lives_ok { $run = $queue->get_run('Project1', 'Branch1', 'Revision1') }
48 'Getting an existing branch lives';
49 isa_ok($run, 'Fumo::Queue::Run');
51 # does the run contain what it should?
54 project => 'Project1',
56 revision => 'Revision1',
60 for my $field (keys %hopefor) {
63 cmp_ok($run->$field, 'eq', $hopefor{$field},
64 "'$field' is corrent for run ($hopefor{$field})");
68 # try updating the run
73 lives_ok { $queue->put_run($run) } 'Adding new run to queue lives';
75 # this will do another DB lookup
76 my $copy_of_run = $queue->get_run('Project1', 'Branch1', 'Revision1');
77 cmp_ok $copy_of_run->weight(), '==', 110,
81 # try and add the same run (it will actually do an update)
83 lives_ok { $queue->put_run($run) }
84 'Adding identical run to queue lives';
89 lives_ok { $queue->delete($run) } 'Deleting a run lives';
90 cmp_ok $queue->count(), '==', 0, 'Queue count is 0 again';
97 $queue->put_run(Fumo::Queue::Run->new({
98 project => "project$_",
99 branch => "branch1$_",
100 revision => "revision$_"
102 } "Adding new run ($_) to queue";
106 while (my $incr = $queue->all_runs()) {
109 cmp_ok $ctr, '==', $_, "all_runs returns $_ results";
115 lives_ok { $queue->delete($_) while $_ = $queue->all_runs() }
116 'Deleting all runs with all_runs() lives ok';
117 cmp_ok $queue->count(), '==', 0, 'Queue count is 0 again';