Skip to content

Commit

Permalink
Perltidy, and check for DBD::Pg in test02.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdybedahl committed Mar 16, 2015
1 parent 2f007d6 commit c751caf
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 422 deletions.
91 changes: 48 additions & 43 deletions t/test01.t
Expand Up @@ -2,66 +2,71 @@ use strict;
use warnings;
use 5.14.2;

use Test::More; # see done_testing()
use Test::More; # see done_testing()

# Require Zonemaster::WebBackend::Engine.pm test
use_ok( 'Zonemaster::WebBackend::Engine' );

# Create Zonemaster::WebBackend::Engine object
my $engine = Zonemaster::WebBackend::Engine->new({ db => 'Zonemaster::WebBackend::DB::SQLite'} );
isa_ok($engine, 'Zonemaster::WebBackend::Engine');
my $engine = Zonemaster::WebBackend::Engine->new( { db => 'Zonemaster::WebBackend::DB::SQLite' } );
isa_ok( $engine, 'Zonemaster::WebBackend::Engine' );

# create a new memory SQLite database
ok($engine->{db}->create_db());
ok( $engine->{db}->create_db() );

# add test user
ok($engine->add_api_user({username => "zonemaster_test", api_key => "zonemaster_test's api key"}) == 1);
ok(scalar($engine->{db}->dbh->selectrow_array(q/SELECT * FROM users WHERE user_info like '%zonemaster_test%'/)) == 1);
ok( $engine->add_api_user( { username => "zonemaster_test", api_key => "zonemaster_test's api key" } ) == 1 );
ok(
scalar( $engine->{db}->dbh->selectrow_array( q/SELECT * FROM users WHERE user_info like '%zonemaster_test%'/ ) ) ==
1 );

# add a new test to the db
my $frontend_params_1 = {
client_id => 'Zonemaster CGI/Dancer/node.js', # free string
client_version => '1.0', # free version like string

domain => 'afnic.fr', # content of the domain text field
advanced => 1, # 0 or 1, is the advanced options checkbox checked
ipv4 => 1, # 0 or 1, is the ipv4 checkbox checked
ipv6 => 1, # 0 or 1, is the ipv6 checkbox checked
profile => 'test_profile_1', # the id if the Test profile listbox
nameservers => [ # list of the namaserves up to 32
{ ns => 'ns1.nic.fr', ip => '1.1.1.1'}, # key values pairs representing nameserver => namesterver_ip
{ ns => 'ns2.nic.fr', ip => '192.134.4.1'},
],
ds_digest_pairs => [ # list of DS/Digest pairs up to 32
{ algorithm => 'sha1', digest => '0123456789012345678901234567890123456789'}, # key values pairs representing ds => digest
{ algorithm => 'sha256', digest => '0123456789012345678901234567890123456789012345678901234567890123'}, # key values pairs representing ds => digest
],
client_id => 'Zonemaster CGI/Dancer/node.js', # free string
client_version => '1.0', # free version like string

domain => 'afnic.fr', # content of the domain text field
advanced => 1, # 0 or 1, is the advanced options checkbox checked
ipv4 => 1, # 0 or 1, is the ipv4 checkbox checked
ipv6 => 1, # 0 or 1, is the ipv6 checkbox checked
profile => 'test_profile_1', # the id if the Test profile listbox
nameservers => [ # list of the namaserves up to 32
{ ns => 'ns1.nic.fr', ip => '1.1.1.1' }, # key values pairs representing nameserver => namesterver_ip
{ ns => 'ns2.nic.fr', ip => '192.134.4.1' },
],
ds_digest_pairs => [ # list of DS/Digest pairs up to 32
{ algorithm => 'sha1', digest => '0123456789012345678901234567890123456789' }
, # key values pairs representing ds => digest
{ algorithm => 'sha256', digest => '0123456789012345678901234567890123456789012345678901234567890123' }
, # key values pairs representing ds => digest
],
};
ok($engine->start_domain_test($frontend_params_1) == 1);
ok(scalar($engine->{db}->dbh->selectrow_array(q/SELECT id FROM test_results WHERE id=1/)) == 1);
ok( $engine->start_domain_test( $frontend_params_1 ) == 1 );
ok( scalar( $engine->{db}->dbh->selectrow_array( q/SELECT id FROM test_results WHERE id=1/ ) ) == 1 );

# test test_progress API
ok($engine->test_progress(1) == 0);
ok( $engine->test_progress( 1 ) == 0 );

require_ok('Zonemaster::WebBackend::Runner');
my $command = qq/perl -MZonemaster::WebBackend::Runner -E'Zonemaster::WebBackend::Runner->new\(\{ db => "Zonemaster::WebBackend::DB::SQLite"\} \)->run\(1\)'/;
system ("$command &");
require_ok( 'Zonemaster::WebBackend::Runner' );
my $command =
qq/perl -MZonemaster::WebBackend::Runner -E'Zonemaster::WebBackend::Runner->new\(\{ db => "Zonemaster::WebBackend::DB::SQLite"\} \)->run\(1\)'/;
system( "$command &" );

sleep(5);
ok($engine->test_progress(1) > 0);
sleep( 5 );
ok( $engine->test_progress( 1 ) > 0 );

foreach my $i (1..12) {
sleep(5);
my $progress = $engine->test_progress(1);
print STDERR "pregress: $progress\n";
last if ($progress == 100);
foreach my $i ( 1 .. 12 ) {
sleep( 5 );
my $progress = $engine->test_progress( 1 );
print STDERR "pregress: $progress\n";
last if ( $progress == 100 );
}
ok($engine->test_progress(1) == 100);
my $test_results = $engine->get_test_results({ id => 1, language => 'fr-FR' });
ok(defined $test_results->{id}, 'TEST1 $test_results->{id} defined');
ok(defined $test_results->{params}, 'TEST1 $test_results->{params} defined');
ok(defined $test_results->{creation_time}, 'TEST1 $test_results->{creation_time} defined');
ok(defined $test_results->{results}, 'TEST1 $test_results->{results} defined');
ok(scalar(@{$test_results->{results}}) > 1, 'TEST1 got some results');
ok( $engine->test_progress( 1 ) == 100 );
my $test_results = $engine->get_test_results( { id => 1, language => 'fr-FR' } );
ok( defined $test_results->{id}, 'TEST1 $test_results->{id} defined' );
ok( defined $test_results->{params}, 'TEST1 $test_results->{params} defined' );
ok( defined $test_results->{creation_time}, 'TEST1 $test_results->{creation_time} defined' );
ok( defined $test_results->{results}, 'TEST1 $test_results->{results} defined' );
ok( scalar( @{ $test_results->{results} } ) > 1, 'TEST1 got some results' );

done_testing();
done_testing();
4 changes: 4 additions & 0 deletions t/test02.t
Expand Up @@ -5,10 +5,14 @@ use 5.14.2;
use Test::More; # see done_testing()

my $can_use_threads = eval 'use threads; 1';
my $can_use_pg = eval 'use DBD::Pg; 1';

if ( not $can_use_threads ) {
plan skip_all => 'No threads in this perl.';
}
elsif ( not $can_use_pg) {
plan skip_all => 'Could not load DBD::Pg.';
}
else {
use_ok( 'Zonemaster::WebBackend::Engine' );

Expand Down
2 changes: 1 addition & 1 deletion t/test03.t
Expand Up @@ -11,7 +11,7 @@ if ( not $can_use_threads ) {
}
else {
# Require Zonemaster::WebBackend::Engine.pm test
require_ok( 'Zonemaster::WebBackend::Engine' );
use_ok( 'Zonemaster::WebBackend::Engine' );

#require Zonemaster::WebBackend::Engine;

Expand Down

0 comments on commit c751caf

Please sign in to comment.