Skip to content

Commit

Permalink
Add tests for carryover flags
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Nov 15, 2023
1 parent 54a74bf commit cac646d
Showing 1 changed file with 48 additions and 27 deletions.
75 changes: 48 additions & 27 deletions t/17-labels_carry_over.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,28 @@ sub comments ($url) {
}

sub restart_with_result ($old_job, $result) {
# this only works properly for passed tests, as the new test won't have any failed test modules listed
# that would make it find a carryover candidate with matching test modules
$t->post_ok("/api/v1/jobs/$old_job/restart", $auth)->status_is(200);
my $res = decode_json($t->tx->res->body);
my $new_job = $res->{result}[0]->{$old_job};
$t->post_ok("/api/v1/jobs/$new_job/set_done", $auth => form => {result => $result})->status_is(200);
return $res;
}

my $old_job = 99962;
my $job = 99963;

$schema->txn_begin;

subtest '"happy path": failed->failed carries over last issue reference' => sub {
my $label = 'label:false_positive';
my $second_label = 'bsc#1234';
my $simple_comment = 'just another simple comment';
for my $comment ($label, $second_label, $simple_comment) {
$t->post_ok('/api/v1/jobs/99962/comments', $auth => form => {text => $comment})->status_is(200);
$t->post_ok("/api/v1/jobs/$old_job/comments", $auth => form => {text => $comment})->status_is(200);
}
my @comments_previous = @{comments('/tests/99962')};
my @comments_previous = @{comments("/tests/$old_job")};
is(scalar @comments_previous, 3, 'all entered comments found');
like($comments_previous[0], qr/\Q$label/, 'comment present on previous test result');
is($comments_previous[2], $simple_comment, 'another comment present');
Expand All @@ -61,8 +66,8 @@ subtest '"happy path": failed->failed carries over last issue reference' => sub

subtest 'carry over prevented via job group settings' => sub {
$group->update({carry_over_bugrefs => 0});
$t->post_ok('/api/v1/jobs/99963/set_done', $auth => form => {result => 'failed'})->status_is(200);
is_deeply(comments('/tests/99963'), [], 'no bugrefs carried over');
$t->post_ok("/api/v1/jobs/$job/set_done", $auth => form => {result => 'failed'})->status_is(200);
is_deeply(comments("/tests/$job"), [], 'no bugrefs carried over');
};

subtest 'carry over enabled in job group settings, note about hook script' => sub {
Expand All @@ -73,56 +78,72 @@ subtest '"happy path": failed->failed carries over last issue reference' => sub
$t->app->log->level('debug');
$group->update({carry_over_bugrefs => 1});
my $output = combined_from {
$t->post_ok('/api/v1/jobs/99963/set_done', $auth => form => {result => 'failed'})->status_is(200);
$t->post_ok("/api/v1/jobs/$job/set_done", $auth => form => {result => 'failed'})->status_is(200);
};
$t->app->log->level('error');

my @comments_current = @{comments('/tests/99963')};
my @comments_current = @{comments("/tests/$job")};
is(join('', @comments_current), $comment_must . $carry_over_note, 'only one bugref is carried over');
like($comments_current[0], qr/\Q$second_label/, 'last entered bugref found, it is expanded');
like $output, qr{\Q_carry_over_candidate(99963): _failure_reason=amarok:none};
like $output, qr{\Q_carry_over_candidate(99963): checking take over from 99962: _failure_reason=amarok:none};
like $output, qr{\Q_carry_over_candidate(99963): found a good candidate (99962)};
like $output, qr{\Q_carry_over_candidate($job): _failure_reason=amarok:none};
like $output, qr{\Q_carry_over_candidate($job): checking take over from $old_job: _failure_reason=amarok:none};
like $output, qr{\Q_carry_over_candidate($job): found a good candidate ($old_job)};
ok $bugs->find({bugid => 'bsc#1234'}, {limit => 1}),
'bugref inserted as part of comment contents being handled on carryover';
};
};

my ($job, $old_job);

subtest 'failed->passed discards all labels' => sub {
my $res = restart_with_result(99963, 'passed');
$job = $res->{result}[0]->{99963};
my @comments_new = @{comments($res->{test_url}[0]->{99963})};
my $res = restart_with_result($job, 'passed');
my @comments_new = @{comments($res->{test_url}[0]->{$job})};
is(scalar @comments_new, 0, 'no labels carried over to passed');
};

# Reset to a clean state
$schema->txn_rollback;
$schema->resultset('JobGroups')->find(1001)->update({carry_over_bugrefs => 1});
$schema->txn_begin;

subtest 'passed->failed does not carry over old labels' => sub {
my $res = restart_with_result($job, 'failed');
$old_job = $job;
$job = $res->{result}[0]->{$job};
my @comments_new = @{comments($res->{test_url}[0]->{$old_job})};
$t->post_ok("/api/v1/jobs/$old_job/comments", $auth => form => {text => 'bsc#1234'})->status_is(200);
$t->post_ok("/api/v1/jobs/$old_job/set_done", $auth => form => {result => 'passed'})->status_is(200);
foreach my $m ($schema->resultset('Jobs')->find($old_job)->modules->all) {
$m->update({result => 'passed'});
}
$t->post_ok("/api/v1/jobs/$job/set_done", $auth => form => {result => 'failed'})->status_is(200);
my @comments_new = @{comments("/tests/$job")};
is(scalar @comments_new, 0, 'no old labels on new failure');
};

# Reset to a clean state
$schema->txn_rollback;
$schema->txn_begin;

subtest 'failed->failed without labels does not fail' => sub {
my $res = restart_with_result($job, 'failed');
$old_job = $job;
$job = $res->{result}[0]->{$job};
my @comments_new = @{comments($res->{test_url}[0]->{$old_job})};
$t->post_ok("/api/v1/jobs/$job/set_done", $auth => form => {result => 'failed'})->status_is(200);
my @comments_new = @{comments("/tests/$job")};
is(scalar @comments_new, 0, 'nothing there, nothing appears');
};

subtest 'failed->failed labels which are not bugrefs are *not* carried over' => sub {
my $label = 'label:any_label';
$t->post_ok("/api/v1/jobs/$job/comments", $auth => form => {text => $label})->status_is(200);
my $res = restart_with_result($job, 'failed');
$old_job = $job;
my @comments_new = @{comments($res->{test_url}[0]->{$old_job})};
$t->post_ok("/api/v1/jobs/$old_job/comments", $auth => form => {text => 'label:any_label'})->status_is(200);
$t->post_ok("/api/v1/jobs/$job/set_done", $auth => form => {result => 'failed'})->status_is(200);
my @comments_new = @{comments("/tests/$job")};
is(join('', @comments_new), '', 'no simple labels are carried over');
is(scalar @comments_new, 0, 'no simple label present in new result');
};

# Reset to a clean state
$schema->txn_rollback;
$schema->txn_begin;

subtest 'failed->failed flag:carryover comments are carried over' => sub {
$t->post_ok("/api/v1/jobs/$old_job/comments", $auth => form => {text => 'flag:carryover'})->status_is(200);
$t->post_ok("/api/v1/jobs/$job/set_done", $auth => form => {result => 'failed'})->status_is(200);
my @comments_new = @{comments("/tests/$job")};
like(join('', @comments_new), qr(flag:carryover), 'Comment with flag:carryover present in new job');
};

# Reset to a clean state
$schema->txn_rollback;

Expand Down

0 comments on commit cac646d

Please sign in to comment.