Skip to content

Commit

Permalink
tests: use like for testing regexes
Browse files Browse the repository at this point in the history
This gives us better diagnostics when the test fails.
  • Loading branch information
Mic92 committed Aug 21, 2024
1 parent 7de7122 commit 250780a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions t/Hydra/Controller/Job/builds.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ subtest "/job/PROJECT/JOBSET/JOB/shield" => sub {

subtest "/job/PROJECT/JOBSET/JOB/prometheus" => sub {
my $response = request(GET '/job/' . $project->name . '/' . $jobset->name . '/' . $build->job . '/prometheus');

ok($response->is_success, "The page showing the job's prometheus data returns 200.");
my $metrics = $response->content;

ok($metrics =~ m/hydra_job_failed\{.*\} 0/);
ok($metrics =~ m/hydra_job_completion_time\{.*\} [\d]+/);
ok($metrics =~ m/hydra_build_closure_size\{.*\} 96/);
ok($metrics =~ m/hydra_build_output_size\{.*\} 96/);
my $metrics = $response->content;
like($metrics, qr/hydra_job_failed\{.*\} 0/);
like($metrics, qr/hydra_job_completion_time\{.*\} [\d]+/);
like($metrics, qr/hydra_build_closure_size\{.*\} 96/);
like($metrics, qr/hydra_build_output_size\{.*\} 96/);
};

done_testing;
2 changes: 1 addition & 1 deletion t/Hydra/Controller/Jobset/http.t
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ subtest 'Update jobset "job" to have an invalid input type' => sub {
})
);
ok(!$jobsetupdate->is_success);
ok($jobsetupdate->content =~ m/Invalid input type.*valid types:/);
like($jobsetupdate->content, qr/Invalid input type.*valid types:/);
};


Expand Down
2 changes: 1 addition & 1 deletion t/Hydra/Controller/User/dashboard.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ my $cookie = $login->header("set-cookie");
my $my_jobs = request(GET '/dashboard/alice/my-jobs-tab', Accept => 'application/json', Cookie => $cookie);
ok($my_jobs->is_success);
my $content = $my_jobs->content();
ok($content =~ /empty_dir/);
like($content, qr/empty_dir/);
ok(!($content =~ /fails/));
ok(!($content =~ /succeed_with_failed/));
done_testing;
2 changes: 1 addition & 1 deletion t/api-test.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ subtest "evaluation" => sub {
my $build = decode_json(request_json({ uri => "/build/" . $evals->[0]->{builds}->[0] })->content());
is($build->{job}, "job", "The build's job name is job");
is($build->{finished}, 0, "The build isn't finished yet");
ok($build->{buildoutputs}->{out}->{path} =~ /\/nix\/store\/[a-zA-Z0-9]{32}-job$/, "The build's outpath is in the Nix store and named 'job'");
like($build->{buildoutputs}->{out}->{path}, qr/\/nix\/store\/[a-zA-Z0-9]{32}-job$/, "The build's outpath is in the Nix store and named 'job'");

subtest "search" => sub {
my $search_project = decode_json(request_json({ uri => "/search/?query=sample" })->content());
Expand Down

0 comments on commit 250780a

Please sign in to comment.