MT#6551 Cleanup Build script

- remove action test_tap
- only start server on "--run-server"
- make "--webdriver" optional
- remove Sipwise::Base from configure-requirements
agranig/subprof
Gerhard Jungwirth 11 years ago
parent c1c6c3a9ee
commit 5a7caa4f04

@ -1,10 +1,11 @@
use lib 'inc';
use Local::Module::Build qw();
use Local::Module::Build;
my $builder = Local::Module::Build->new(
module_name => 'NGCP::Panel',
license => 'restrictive',
license => 'perl',
dist_version_from => 'lib/NGCP/Panel.pm',
dist_abstract => 'Sipwise Configuration Panel',
tap_harness_args => {
timer => 1,
formatter_class => 'TAP::Formatter::JUnit',
@ -14,7 +15,6 @@ my $builder = Local::Module::Build->new(
'lib' => 0,
'Module::Build' => '0.4004',
'Moose' => 2,
'Sipwise::Base' => 0,
},
requires => {
'base' => 0,
@ -81,6 +81,7 @@ my $builder = Local::Module::Build->new(
'Scalar::Util' => 0,
'Sereal::Decoder' => 0,
'Sereal::Encoder' => 0,
'Sipwise::Base' => 0,
'strict' => 0,
'Template' => 0,
'Text::CSV_XS' => 0,
@ -145,38 +146,43 @@ Build.PL - NGCP-Panel build system including test fixtures
./Build test --webdriver=selenium-rc # from CPAN distro Alien-SeleniumRC
./Build test --webdriver=external --wd-server=127.0.0.1:5555
./Build test_tap --webdriver=external # outputs tap to tap/ folder
./Build testcover --webdriver='phantomjs --webdriver=4444'
./Build test_api
./Build test_api --schema-base-dir=path/to/schema --server=https://1.2.3.4:1443
=head2 Options
--webdriver (required) external webdriver command
--wd-server HOST:PORT of an external webdriver to connect to
--server URI for socket test server
--schema-base-dir directory of NGCP::Schema if its not yet installed
--mysqld-port port where the mysqld should be started
--mysql-dump one or more mysql dumps to be imported to our mysqld
--no-junit don't output junit but normal TAP, for manual testing
--run-server panel should be started by build script
--schema-base-dir directory of NGCP::Schema if its not yet installed
--server URI for socket test server
--webdriver Command to be run as Webdriver
--wd-server HOST:PORT of an external webdriver to connect to
--help brief help message
--man full documentation
=head1 OPTIONS
=head2 C<--webdriver>
=head2 C<--mysqld-port>
(required) command to launch a webdriver
external if the webdriver is launched externally
If this option and C<--mysqld-dir> are supplied, a mysqld will be started
at the specified port and be used for the tests. mysqld will be stopped
and the temporary data deleted when this script finishes.
=head2 C<--wd-server>
=head2 C<--mysql-dump>
Host:Port of the webdriver to which the tests should connect.
Default is set by Test::WebDriver to localhost:4444
If this option and C<--mysqld-port> are supplied, a mysqld will be started
and be used for the tests. It will import all dumps supplied with this option.
This option can be set multiple times. In this case all specified files will
be dumped into the database.
=head2 C<--server>
=head2 C<--run-server>
URI for the HTTP::Server::PSGI socket server run for testing,
default C<http://localhost:5000>
Does not take an argument. Indicates the ./Build script should start a
server running the panel by itself on the Address given by the --server
argument.
=head2 C<--schema-base-dir>
@ -184,18 +190,21 @@ If the NGCP::Schema is not installed to a known path to perl, this
option can specify the base directory of its development location.
It will then be included via blib, so we have access to its lib and share.
=head2 C<--mysqld-port>
=head2 C<--server>
If this option and C<--mysqld-dir> are supplied, a mysqld will be started
at the specified port and be used for the tests. mysqld will be stopped
and the temporary data deleted when this script finishes.
URI for the HTTP::Server::PSGI socket server run for testing,
default C<http://localhost:5000>
=head2 C<--mysql-dump>
=head2 C<--webdriver>
If this option and C<--mysqld-port> are supplied, a mysqld will be started
and be used for the tests. It will import all dumps supplied with this option.
This option can be set multiple times. In this case all specified files will
be dumped into the database.
command to launch a webdriver
external if the webdriver is launched externally
this command is no longer required
=head2 C<--wd-server>
Host:Port of the webdriver to which the tests should connect.
Default is set by Test::WebDriver to localhost:4444
=head2 C<--help>

@ -1,8 +1,7 @@
package Local::Module::Build;
use Sipwise::Base;
use Moose qw(around);
use Moose qw(around extends);
use Child qw(child);
use Capture::Tiny qw(capture);
use Capture::Tiny;
use TryCatch;
use MooseX::Method::Signatures;
use LWP::UserAgent;
@ -10,7 +9,7 @@ extends 'Module::Build';
our ($plackup, $webdriver, @cover_opt, $mysqld);
method wait_socket($host, $port) {
method wait_socket($host, $port, $timeout=90) {
require IO::Socket::IP;
my $timer = 0;
while (1) {
@ -22,8 +21,8 @@ method wait_socket($host, $port) {
last if $sock;
sleep 1;
$timer++;
die sprintf('socket %s:%s is not accessible within 30 seconds after start', $host, $port)
if $timer > 90;
die sprintf('socket %s:%s is not accessible within %d seconds after start', $host, $port, $timeout)
if $timer > $timeout;
};
}
@ -40,14 +39,14 @@ sub _test_preconditions {
my ($self) = @_;
require Getopt::Long;
my %opt = (server => 'http://localhost:5000');
Getopt::Long::GetOptions(\%opt, 'webdriver=s', 'server:s', 'help|?', 'man', 'wd-server=s', 'schema-base-dir=s', 'mysqld-port=s', 'mysql-dump=s@', 'no-junit')
my %opt = (server => 'http://localhost:5000', webdriver => 'external');
Getopt::Long::GetOptions(\%opt, 'webdriver=s', 'server:s', 'help|?', 'man', 'wd-server=s',
'schema-base-dir=s', 'mysqld-port=s', 'mysql-dump=s@', 'no-junit', 'run-server')
or die 'could not process command-line options';
require Pod::Usage;
Pod::Usage::pod2usage(-exitval => 1, -input => 'Build.PL') if $opt{help};
Pod::Usage::pod2usage(-exitval => 0, -input => 'Build.PL', -verbose => 2) if $opt{man};
Pod::Usage::pod2usage("$0: --webdriver option required.\nRun `perldoc Build.PL`") unless $opt{webdriver};
if ($opt{'no-junit'}) {
delete $self->tap_harness_args->{formatter_class};
@ -86,29 +85,37 @@ sub _test_preconditions {
}
require URI;
unless ($opt{server} =~ m|^https?://|) {
die "Wrong format of server argument, should start with 'http(s)'.";
}
my $uri = URI->new($opt{server});
require File::Which;
$ENV{ NGCP_PANEL_CONFIG_LOCAL_SUFFIX } = "testing";
$plackup = child {
my $out_fh = IO::File->new("panel_debug_stdout", "w+");
my $err_fh = IO::File->new("panel_debug_stderr", "w+");
$out_fh->autoflush(1);
$err_fh->autoflush(1);
local $| = 1;
capture {
exec $^X,
'-Ilib',
exists $opt{'schema-base-dir'} ? "-Mblib=$opt{'schema-base-dir'}" : (),
@cover_opt,
scalar File::Which::which('plackup'),
sprintf('--listen=%s:%s', $uri->host, $uri->port),
'ngcp_panel.psgi';
} stdout => $out_fh, stderr => $err_fh;
};
$self->wait_socket($uri->host, $uri->port);
if( $opt{'run-server'} ) {
require File::Which;
$ENV{ NGCP_PANEL_CONFIG_LOCAL_SUFFIX } = "testing";
$plackup = child {
my $out_fh = IO::File->new("panel_debug_stdout", "w+");
my $err_fh = IO::File->new("panel_debug_stderr", "w+");
$out_fh->autoflush(1);
$err_fh->autoflush(1);
local $| = 1;
Capture::Tiny::capture {
exec $^X,
'-Ilib',
exists $opt{'schema-base-dir'} ? "-Mblib=$opt{'schema-base-dir'}" : (),
@cover_opt,
scalar File::Which::which('plackup'),
sprintf('--listen=%s:%s', $uri->host, $uri->port),
'ngcp_panel.psgi';
} stdout => $out_fh, stderr => $err_fh;
};
$self->wait_socket($uri->host, $uri->port);
}
$ENV{CATALYST_SERVER} = $opt{server};
if ($self->verbose) {
print("Server is: ".$opt{server}."\n");
}
}
sub _download_certs {
@ -167,14 +174,6 @@ method ACTION_testcover {
$self->do_system(qw(cover));
}
method ACTION_test_tap {
$self->depends_on('code');
$self->_test_preconditions;
system( "mkdir -p tap" );
$ENV{PERL_TEST_HARNESS_DUMP_TAP} = "tap/";
$self->generic_test(type => 'default');
}
method ACTION_test_servers {
$self->depends_on('code');
$self->_test_preconditions;
@ -205,3 +204,5 @@ method ACTION_readme {
}
END { shutdown_servers }
1;

Loading…
Cancel
Save