[bigtop] r1561 committed - - Added new config test. Test is enabled by setting TEST_CONFIG...

0 views
Skip to first unread message

codesite...@google.com

unread,
May 3, 2011, 2:13:59 PM5/3/11
to gan...@googlegroups.com
Revision: 1561
Author: net.a...@gmail.com
Date: Tue May 3 11:13:05 2011
Log: - Added new config test. Test is enabled by setting TEST_CONFIG
environment variable. It will test the selected gantry config
to make sure there are no missing config items. It will also
alert you to any config items in the gantry config that are not
present in the bigtop file.

http://code.google.com/p/bigtop/source/detail?r=1561

Added:
/trunk/t/bigtop/playship/t/05_config.t
Modified:
/trunk/Changes
/trunk/MANIFEST
/trunk/lib/Bigtop/Backend/Control/Gantry.pm
/trunk/lib/Bigtop.pm
/trunk/t/bigtop/playship/MANIFEST
/trunk/t/dbixclass/01_dbixclass.t
/trunk/t/dbixclass/02_one_model_base.t
/trunk/t/dbixclass/03_pk_stuff.t
/trunk/t/gantry/02_controllers.t
/trunk/t/gantry/04_no_gen.t
/trunk/t/gantry/07_base_cont.t
/trunk/t/gantry/08_soap.t

=======================================
--- /dev/null
+++ /trunk/t/bigtop/playship/t/05_config.t Tue May 3 11:13:05 2011
@@ -0,0 +1,82 @@
+use Test::More;
+use Gantry::Conf ();
+
+plan skip_all => 'set TEST_CONFIG to enable this test' unless
$ENV{TEST_CONFIG};
+
+my @avail_configs = qw/base CGI/;
+my $instances = {
+ base => 'addressbook',
+ CGI => 'addressbook_CGI',
+};
+my $configs = {
+ addressbook => [
+ qw/
+ doc_rootp
+ template_wrapper
+ show_dev_navigation
+ dbconn
+ /
+ ],
+ addressbook_CGI => [
+ qw/
+ app_rootp
+ dbconn
+ /
+ ],
+};
+
+diag( "" );
+diag( "which config would you like to test?" );
+diag( "0. addressbook" );
+diag( "1. addressbook_CGI" );
+diag( "2. None" );
+my $p = <STDIN>;
+chomp( $p );
+
+if ( $p >= 2) {
+ plan skip_all => "config test";
+}
+else {
+ my $instance = $instances->{$avail_configs[$p]};
+ my $gconf;
+
+ # Set number of tests to number of config items to test
+ # plus 1 for the gantry config test.
+ plan tests => scalar( @{$configs->{$instance}} ) + 1;
+
+ diag( "" );
+ diag( "Location of gantry config file [/etc/gantry.conf]: ");
+ my $config_file = <STDIN>;
+ chomp( $config_file );
+
+ unless ($config_file) {
+ $config_file = File::Spec->catfile( qw/ \/ etc gantry.conf / );
+ }
+
+ eval {
+ $gconf = Gantry::Conf->retrieve(
+ {
+ instance => "$instance",
+ config_file => "$config_file",
+ }
+ );
+ };
+
+ ok(! $@, 'loaded gantry config');
+
+ # Warn about any items found in the gantry config that are missing
+ # from the app.
+ foreach my $item (@{$configs->{$instance}}) {
+ is( exists $gconf->{$item}, 1, "$item found in config" );
+ delete $gconf->{$item};
+ }
+
+ if (scalar(keys %$gconf)) {
+ diag( "" );
+ diag( 'The following config items were found but are not present
in the app config' );
+ }
+
+ foreach my $item (keys %$gconf) {
+ diag( $item );
+ }
+}
=======================================
--- /trunk/Changes Fri Apr 8 12:30:27 2011
+++ /trunk/Changes Tue May 3 11:13:05 2011
@@ -1,5 +1,12 @@
Revision history for Perl extension Bigtop.

+0.43
+ - Added new config test. Test is enabled by setting TEST_CONFIG
+ environment variable. It will test the selected gantry config
+ to make sure there are no missing config items. It will also
+ alert you to any config items in the gantry config that are not
+ present in the bigtop file.
+
0.42
- Fixed inadvertent author / copyright change in AddressBook test.

=======================================
--- /trunk/MANIFEST Fri Apr 8 11:57:26 2011
+++ /trunk/MANIFEST Tue May 3 11:13:05 2011
@@ -254,6 +254,7 @@
t/bigtop/playship/t/02_pod.t
t/bigtop/playship/t/03_podcover.t
t/bigtop/playship/t/04_manifest.t
+t/bigtop/playship/t/05_config.t
t/bigtop/playship/t/10_run.t
t/cdbi/01_cdbisweet.t
t/cdbi/02_one_model_base.t
=======================================
--- /trunk/lib/Bigtop/Backend/Control/Gantry.pm Fri Apr 8 11:57:26 2011
+++ /trunk/lib/Bigtop/Backend/Control/Gantry.pm Tue May 3 11:13:05 2011
@@ -716,6 +716,95 @@
ok_manifest();
[% END %]

+[% BLOCK config_test %]
+use Test::More;
+use Gantry::Conf ();
+
+plan skip_all => 'set TEST_CONFIG to enable this test' unless
$ENV{TEST_CONFIG};
+
+my @avail_configs = qw/[% configs.keys.sort.join(' ') %]/;
+my $instances = {
+[% FOREACH instance IN instances.keys %]
+ [% instance %] => '[% instances.$instance %]',
+[% END %]
+};
+my $configs = {
+[% FOREACH config IN configs.keys %]
+ [% instances.$config %] => [
+ qw/
+
+ [%- FOREACH item IN configs.$config.keys %]
+ [% item %]
+
+
+ [%- END %]
+ /
+ ],
+[% END %]
+};
+
+diag( "" );
+diag( "which config would you like to test?" );
+[% FOREACH config IN configs.keys.sort %]
+diag( "[% loop.count - 1 %]. [% instances.$config %]" );
+
+ [%- IF loop.last %]
+diag( "[% loop.count %]. None" );
+ [%- END %]
+[% END %]
+
+my $p = <STDIN>;
+chomp( $p );
+
+if ( $p >= [% configs.keys.size %]) {
+ plan skip_all => "config test";
+}
+else {
+ my $instance = $instances->{$avail_configs[$p]};
+ my $gconf;
+
+ # Set number of tests to number of config items to test
+ # plus 1 for the gantry config test.
+ plan tests => scalar( @{$configs->{$instance}} ) + 1;
+
+ diag( "" );
+ diag( "Location of gantry config file [/etc/gantry.conf]: ");
+ my $config_file = <STDIN>;
+ chomp( $config_file );
+
+ unless ($config_file) {
+ $config_file = File::Spec->catfile( qw/ \/ etc gantry.conf / );
+ }
+
+ eval {
+ $gconf = Gantry::Conf->retrieve(
+ {
+ instance => "$instance",
+ config_file => "$config_file",
+ }
+ );
+ };
+
+ ok(! $@, 'loaded gantry config');
+
+ # Warn about any items found in the gantry config that are missing
+ # from the app.
+ foreach my $item (@{$configs->{$instance}}) {
+ is( exists $gconf->{$item}, 1, "$item found in config" );
+ delete $gconf->{$item};
+ }
+
+ if (scalar(keys %$gconf)) {
+ diag( "" );
+ diag( 'The following config items were found but are not present
in the app config' );
+ }
+
+ foreach my $item (keys %$gconf) {
+ diag( $item );
+ }
+}
+[% END %]
+
[% BLOCK run_test %]
use strict;
use warnings;
@@ -1851,7 +1940,7 @@
$base_model = $app_name . '::Model';
$dbix = 1;
}
-
+
if ( defined $base_controller->[0] and $base_controller->[0] ) {
# warn "skipping previously generated modules\n";
$bigtop_tree->walk_postorder(
@@ -2046,6 +2135,47 @@
);
};
warn $@ if ( $@ );
+
+ # Make the config test, unless they asked not to
+ if ( not defined $config_block->{ config_test }
+ or
+ $config_block->{ config_test } )
+ {
+ my $instance = $bigtop_tree->get_config->{Conf}->{instance};
+ my $instances;
+
+ foreach my $conf_type ( @{ $bigtop_tree->get_app_config_types } ) {
+ my $name = $instance;
+
+ if ( $conf_type eq 'base' ) {
+ $name = $instance;
+ }
+ else {
+ $name .= "_$conf_type"
+ }
+
+ $instances->{$conf_type} = $name;
+ }
+
+
+ my $config_test_file = File::Spec->catfile(
+ $test_dir, '05_config.t'
+ );
+ my $config_test_content =
Bigtop::Backend::Control::Gantry::config_test(
+ {
+ configs => $config_values,
+ instances => $instances
+ }
+ );
+
+ eval {
+ no warnings qw( Bigtop );
+ Bigtop::write_file(
+ $config_test_file, $config_test_content,
+ );
+ };
+ warn $@ if ( $@ );
+ }

# finally, make the run test, unless they asked not to
if ( not defined $config_block->{ run_test }
@@ -2548,7 +2678,7 @@

my $pod = Bigtop::Backend::Control::Gantry::pod(
{
- app_name => $data->{app_name},
+ app_name => $data->{app_name},
accessors => $accessor_configs,
package_name => $package_name,
methods => $stub_method_names,
@@ -3442,12 +3572,12 @@
my ( $arg_capture, @doc_args )
= _build_arg_capture( @{ $choices->{extra_args} } );

-
+
my @literals;
foreach my $literal ( @{ $choices->{literal} } ) {
push( @literals, $literal );
}
-
+
my %authed_methods;
if ( $choices->{authed_methods} ) {
foreach my $pair ( @{ $choices->{authed_methods} } ) {
@@ -3455,15 +3585,15 @@
$authed_methods{ $key } = $value;
}
}
-
+
my @permissions;
if ( $choices->{permissions} ) {
foreach my $pair ( @{ $choices->{permissions} } ) {
my ( $key, $value );
-
+
if ( ref( $pair ) eq 'HASH' ) { ( $key, $value ) = %{ $pair };
}
else { $key = $pair;
}
-
+
if ( $key !~ /[crud-]+/ or length( $key ) ne 12 ) {
die "invalid permission bits, $key ( usage: crudcrudcrud
)\n"
. "at " . $self->get_controller_name . "\n";
@@ -3473,7 +3603,7 @@
push( @permissions, $value );
}
}
-
+
my $config_hashref = Bigtop::Backend::Control::Gantry::hashref(
{
authed_methods => \%authed_methods,
@@ -3648,9 +3778,9 @@
$perms = $choices->{ header_option_perms }->one_hash();
}

- $header_options = _build_options(
- {
- options => $choices->{header_options},
+ $header_options = _build_options(
+ {
+ options => $choices->{header_options},
url_suffix => $url_suffix,
perms => $perms,
}
@@ -3679,7 +3809,7 @@
}
$row_options = _build_options(
{
- options => $choices->{ row_options },
+ options => $choices->{ row_options },
row_options => 1,
perms => $perms,
}
@@ -3980,7 +4110,7 @@
{
die "Error: I can't generate AutoCRUD_form for $name_of{method} "
. "of controller $name_of{controller}.\n"
- . " No fields (or all_fields_but) were given.\n";
+ . " No fields (or all_fields_but) were given.\n";
}

my $requested_fields;
=======================================
--- /trunk/lib/Bigtop.pm Fri Apr 8 12:30:27 2011
+++ /trunk/lib/Bigtop.pm Tue May 3 11:13:05 2011
@@ -5,7 +5,7 @@
use Carp;
use File::Spec;

-our $VERSION = '0.42';
+our $VERSION = '0.43';

sub write_file {
my $file_name = shift;
=======================================
--- /trunk/t/bigtop/playship/MANIFEST Fri Apr 8 11:57:26 2011
+++ /trunk/t/bigtop/playship/MANIFEST Tue May 3 11:13:05 2011
@@ -29,4 +29,5 @@
t/02_pod.t
t/03_podcover.t
t/04_manifest.t
+t/05_config.t
t/10_run.t
=======================================
--- /trunk/t/dbixclass/01_dbixclass.t Sat Jun 6 05:13:35 2009
+++ /trunk/t/dbixclass/01_dbixclass.t Tue May 3 11:13:05 2011
@@ -44,7 +44,7 @@
Model GantryDBIxClass {
extra_components `InflateColumn::DateTime`;
}
- Control Gantry { dbix 1; full_use 1; }
+ Control Gantry { dbix 1; full_use 1; config_test 0; }
SQL Postgres { }
SQL MySQL { }
SQL SQLite { }
=======================================
--- /trunk/t/dbixclass/02_one_model_base.t Wed Apr 11 14:11:44 2007
+++ /trunk/t/dbixclass/02_one_model_base.t Tue May 3 11:13:05 2011
@@ -24,7 +24,7 @@
template_engine TT;
app_dir ``;
Model GantryDBIxClass { model_base_class
Exotic::Base::Module; }
- Control Gantry { dbix 1; full_use 1; run_test 0; }
+ Control Gantry { dbix 1; full_use 1; run_test 0; config_test
0; }
SQL Postgres { }
SQL MySQL { }
}
=======================================
--- /trunk/t/dbixclass/03_pk_stuff.t Tue Jan 2 08:57:22 2007
+++ /trunk/t/dbixclass/03_pk_stuff.t Tue May 3 11:13:05 2011
@@ -29,7 +29,7 @@
template_engine TT;
app_dir ``;
Model GantryDBIxClass { }
- Control Gantry { dbix 1; full_use 1; }
+ Control Gantry { dbix 1; full_use 1; config_test 0; }
SQL Postgres { }
SQL MySQL { }
}
=======================================
--- /trunk/t/gantry/02_controllers.t Thu May 14 14:56:25 2009
+++ /trunk/t/gantry/02_controllers.t Tue May 3 11:13:05 2011
@@ -46,7 +46,7 @@
engine MP20;
plugins PluginQ;
template_engine TT;
- Control Gantry { full_use 1; }
+ Control Gantry { full_use 1; config_test 0; }
SQL Postgres { no_gen 1; }
HttpdConf Gantry { }
SiteLook GantryDefault { }
@@ -256,7 +256,7 @@
config {
engine MP20;
template_engine TT;
- Control Gantry { }
+ Control Gantry { config_test 0; }
}
app Apps::Checkbook {
authors `Somebody Somewhere` => `somebody\@example.com`;
=======================================
--- /trunk/t/gantry/04_no_gen.t Fri Apr 8 11:57:26 2011
+++ /trunk/t/gantry/04_no_gen.t Tue May 3 11:13:05 2011
@@ -29,7 +29,7 @@
base_dir `$play_dir`;
engine MP20;
template_engine TT;
- Control Gantry { }
+ Control Gantry { config_test 0; }
}
app Apps::Checkbook {
authors `Somebody Somewhere` => `$email`;
=======================================
--- /trunk/t/gantry/07_base_cont.t Tue Jan 2 08:50:55 2007
+++ /trunk/t/gantry/07_base_cont.t Tue May 3 11:13:05 2011
@@ -23,7 +23,7 @@
template_engine TT;
SQL SQLite {}
CGI Gantry { gen_root 1; with_server 1; flex_db 1; }
- Control Gantry { dbix 1; }
+ Control Gantry { dbix 1; config_test 0; }
SiteLook GantryDefault {}
}
app Sample {
=======================================
--- /trunk/t/gantry/08_soap.t Tue Jan 8 14:39:02 2008
+++ /trunk/t/gantry/08_soap.t Tue May 3 11:13:05 2011
@@ -25,7 +25,7 @@
base_dir `$play_dir`;
engine MP20;
template_engine TT;
- Control Gantry { }
+ Control Gantry { config_test 0; }
}
app Apps::Checkbook {
authors `Phil Crow` => `mail\@example.com`;

Reply all
Reply to author
Forward
0 new messages