| 1 | package Test::Zapp; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use Mojo::Base 'Test::Mojo'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use Mojo::JSON qw( encode_json ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Mojo::File qw( tempdir ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Mojo::Home; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Zapp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 16 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | # Test Zapp itself by default | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 16 | ▶ | if ( !@_ || ( ref $_[0] && !blessed $_[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not @_ or ref $_[0] and not builtin::blessed($_[0])
ref $_[0] and not builtin::blessed($_[0])
MC/DC0%0/3
not @_ or ref $_[0] and not builtin::blessed($_[0])
not @_
ref $_[0]
not builtin::blessed($_[0])
Truth table25%1/4
not(A) or B and not(C)
A= not @_B= ref $_[0]C= not builtin::blessed($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | unshift @_, Zapp->new( | |||||||||||||||||||||||||||||||||||||||||
| 16 | home => Mojo::Home->new( tempdir ), | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | my $t = $class->SUPER::new( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $t->app->ua( $t->ua ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | return $t; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | sub render_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ( $self, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_ok: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my @tmpl; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $name = 'render template succeeds'; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $args[0] eq 'inline' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | @tmpl = ( shift @args, shift @args ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ( @args % 2 == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $name = pop @args; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $output = $self->app->build_controller->render_to_string( @tmpl, @args ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->test( ok => !$@, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ( !$self->success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | diag "Render error: $@"; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # Magic up a TX and response so that Test::Mojo methods work | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->tx( $self->ua->build_tx( GET => '/render_ok' ) ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $res = $self->tx->res; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $res->code( 200 ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $res->message( "Ok" ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $res->content->asset->add_chunk( $output ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | sub run_queue { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_queue: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | # Run all tasks on the queue | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $worker = $self->app->minion->worker->register; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | while ( my $job = $worker->dequeue(0) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $e = $job->execute; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->test( 'ok', !$e, 'job executed successfully' ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $self->or( sub { diag "Job error: ", explain $e } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | last if $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $worker->unregister; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub run_task { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my ( $self, $task_class, $input, $context, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_task: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( !ref $context ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $name = $context; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $context = []; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # XXX: We no longer need to create a plan to create a run | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $plan = $self->{zapp}{plan} = $self->app->create_plan({ | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$name // "Test $task_class"
MC/DC0%0/1
$name // "Test $task_class"
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | label => $name // "Test $task_class", | ||||||||||||||||||||||||||||||||||||||||||
| 77 | tasks => [ | ||||||||||||||||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | name => $task_class, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | class => $task_class, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | input => encode_json( $input ), | ||||||||||||||||||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 84 | inputs => $context, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | my $run = $self->{zapp}{run} = $self->app->enqueue_plan( | ||||||||||||||||||||||||||||||||||||||||||
| 87 | $plan->{plan_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | { map $_->@{qw( name value )}, @$context }, | |||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $worker = $self->app->minion->worker->register; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $job = $self->{zapp}{job} = $worker->dequeue; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $e = $job->execute; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->test( 'ok', !$e, 'job executed successfully' ); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $self->or( sub { diag "Job error: ", explain $e } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $worker->unregister; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | sub task_output_is { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my ( $self, $key, $output, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
task_output_is: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $result = $self->{zapp}{job}->info->{result}; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ( !ref $key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $result = $result->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $name = $output; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $output = $key; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | undef $key; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->test( 'is_deeply', $result, $output, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | sub task_output_like { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my ( $self, $key, $output, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
task_output_like: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $result = $self->{zapp}{job}->info->{result}{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->test( 'like', $result, $output, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | sub task_info_is { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my ( $self, $info_key, $info_value, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
task_info_is: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->test( 'is', $self->{zapp}{job}->info->{$info_key}, $info_value, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | sub clear_backend { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_backend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->Test::Yancy::clear_backend; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->app->minion->reset({ all => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | sub Test::Yancy::clear_backend { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_backend: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my %tables = ( | |||||||||||||||||||||||||||||||||||||||||
| 136 | zapp_plans => 'plan_id', | ||||||||||||||||||||||||||||||||||||||||||
| 137 | zapp_plan_inputs => [ 'plan_id', 'name' ], | ||||||||||||||||||||||||||||||||||||||||||
| 138 | zapp_plan_tasks => 'task_id', | ||||||||||||||||||||||||||||||||||||||||||
| 139 | zapp_plan_task_parents => [ 'task_id', 'parent_task_id' ], | ||||||||||||||||||||||||||||||||||||||||||
| 140 | zapp_runs => 'run_id', | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | for my $table ( keys %tables ) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $id_field = $tables{ $table }; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | for my $item ( $self->app->yancy->list( $table ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 145 | my $id = ref $id_field eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ? { map { $_ => $item->{ $_ } } @$id_field } | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | : $item->{ $id_field } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->app->yancy->backend->delete( $table => $id ); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | __END__ | ||||||||||||||||||||||||||||||||||||||||||