Skip to content
Permalink
Browse files

allow specifying sitename in shortened form

  • Loading branch information...
haarg committed Sep 4, 2009
1 parent 72f703b commit 7a910a076239f4e730f52a1d840d15628d2cb2fc
Showing with 35 additions and 3 deletions.
  1. +2 −1 lib/WGDev/Command.pm
  2. +30 −1 t/03_WGDev-Command.t
  3. +3 −1 t/testdata/www.example.com.conf
@@ -206,12 +206,13 @@ sub set_config_by_sitename {
require Config::JSON;
my @configs = $wgd->list_site_configs;
my $found_config;
my $sitename_regex = qr/ (?:^|[.]) \Q$sitename\E $ /msx;
for my $config_file (@configs) {
my $config = eval { Config::JSON->new($config_file) };
next
if !$config;
for my $config_sitename ( @{ $config->get('sitename') } ) {
if ( $config_sitename eq $sitename ) {
if ( $config_sitename =~ m/$sitename_regex/msx ) {
if ($found_config) {
WGDev::X->throw("Ambigious site name: $sitename");
}
@@ -375,7 +375,7 @@ my $config2_abs = catfile($etc, 'www.example2.com.conf');
open my $fh, '<', catfile($test_data, 'www.example.com.conf');
my $config_data = $json->decode(scalar do { local $/; <$fh> });
close $fh;
$config_data->{sitename} = ['www.example2.com', 'www.example.com'];
$config_data->{sitename} = ['www.example2.com', 'www.example.com', 'www.example4.com', 'example5.com'];
open $fh, '>', $config2_abs;
print {$fh} $json->encode($config_data);
close $fh;
@@ -392,11 +392,40 @@ my $config2_abs = catfile($etc, 'www.example2.com.conf');
}
'guess_webgui_paths finds config file when given sitename';

lives_and {
is_path +WGDev::Command->guess_webgui_paths(
wgd => WGDev->new,
root => $root,
sitename => 'example2.com',
)->config_file, $config2_abs;
}
'guess_webgui_paths finds config file when given shortened sitename';

throws_ok {
WGDev::Command->guess_webgui_paths( wgd => WGDev->new, root => $root, sitename => 'www.example.com' )
} 'WGDev::X',
'guess_webgui_paths throws error for ambiguous sitenames';

throws_ok {
WGDev::Command->guess_webgui_paths( wgd => WGDev->new, root => $root, sitename => 'w.example2.com' )
} 'WGDev::X',
q{guess_webgui_paths throws error for shortened sitename that isn't shortened on domain boundary};

throws_ok {
WGDev::Command->guess_webgui_paths( wgd => WGDev->new, root => $root, sitename => 'www.example2' )
} 'WGDev::X',
q{guess_webgui_paths throws error for shortened sitename that is shortened on the wrong end};

throws_ok {
WGDev::Command->guess_webgui_paths( wgd => WGDev->new, root => $root, sitename => 'example4.com' )
} 'WGDev::X',
'guess_webgui_paths throws error for ambiguous shortened sitename';

throws_ok {
WGDev::Command->guess_webgui_paths( wgd => WGDev->new, root => $root, sitename => 'example5.com' )
} 'WGDev::X',
'guess_webgui_paths throws error for ambiguous sitenames even when exact match exists';

throws_ok {
WGDev::Command->guess_webgui_paths( wgd => WGDev->new, root => $root, sitename => 'www.newexample.com' )
} 'WGDev::X',
@@ -6,6 +6,8 @@
"dsn" : "DBI:mysql:www_example_com",
"gateway" : "/",
"sitename" : [
"www.example.com"
"www.example.com",
"www2.example4.com",
"www.example5.com"
],
}

0 comments on commit 7a910a0

Please sign in to comment.
You can’t perform that action at this time.