File: linkcheck.t

package info (click to toggle)
libminion-perl 9.09%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,016 kB
  • sloc: perl: 1,097; makefile: 9
file content (43 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use Mojo::Base -strict;

use Test::More;

# This test requires a PostgreSQL connection string for an existing database
#
#   TEST_ONLINE=postgres://tester:testing@/test script/linkcheck test
#
plan skip_all => 'set TEST_ONLINE to enable this test' unless $ENV{TEST_ONLINE};

use Mojo::Pg;
use Mojo::URL;
use Test::Mojo;

# Isolate tests
my $url
  = Mojo::URL->new($ENV{TEST_ONLINE})->query([search_path => 'linkcheck_test']);
my $pg = Mojo::Pg->new($url);
$pg->db->query('drop schema if exists linkcheck_test cascade');
$pg->db->query('create schema linkcheck_test');

# Override configuration for testing
my $t = Test::Mojo->new(LinkCheck => {pg => $url, secrets => ['test_s3cret']});
$t->ua->max_redirects(10);

# Enqueue a background job
$t->get_ok('/')->status_is(200)->text_is('title' => 'Check links')
  ->element_exists('form input[type=url]');
$t->post_ok('/links' => form => {url => 'https://mojolicious.org'})
  ->status_is(200)->text_is('title' => 'Result')
  ->text_is('p' => 'Waiting for result...')->element_exists_not('table');

# Perform the background job
$t->get_ok('/links/1')->status_is(200)->text_is('title' => 'Result')
  ->text_is('p' => 'Waiting for result...')->element_exists_not('table');
$t->app->minion->perform_jobs;
$t->get_ok('/links/1')->status_is(200)->text_is('title' => 'Result')
  ->element_exists_not('p')->element_exists('table');

# Clean up once we are done
$pg->db->query('drop schema linkcheck_test cascade');

done_testing();