
jgottshall at capwiz
Sep 17, 2008, 3:12 PM
Views: 2482
Permalink
|
|
subdomain hook for Catalyst::Test
|
|
Our app allows for virtual subdomains that (among other things) enable specific behaviors in the app. For example, http://www.myapp.com/foo/bar and http://magic.myapp.com/foo/bar both point to same app, but the latter has "magic" behaviors associated with it. The problem is that we're having trouble writing tests against specific behaviors in our controller tests, particularly when we want to test several different subdomains within the same script. My current solution is to set an environment variable in the test script specifing the desired subdomain. I've added hooks to the app that will use this value if available, so that controller tests using a "local" instance of the app instantiated with Catalyst::Test and a faked request will Just Work. But we run into trouble when we try to run the tests against a "remote" server by setting CATALYST_SERVER. The env var setting embedded in the script obviously is not visible to the server instance that's running remotely. In order to remedy this problem, I've patched Catalyst::Test to look for my new env var and prepend it to the CATALYST_SERVER host component. It works great! But I'm wondering whether this patch is worthy of adding to the core, or if there's a different way I should be approaching the problem. Here's a diff against 5.70/trunk: Index: lib/Catalyst/Test.pm =================================================================== --- lib/Catalyst/Test.pm (revision 8432) +++ lib/Catalyst/Test.pm (working copy) @@ -148,6 +148,10 @@ my $request = Catalyst::Utils::request( shift(@_) ); my $server = URI->new( $ENV{CATALYST_SERVER} ); + if ( $ENV{CATALYST_SUBDOMAIN} ) { + $server->host("$ENV{CATALYST_SUBDOMAIN}." . $server->host); + } + if ( $server->path =~ m|^(.+)?/$| ) { my $path = $1; $server->path("$path") if $path; # need to be quoted If this approach makes sense, I'll add documentation to the patch, of course. I may need a little help coming up with a working test, though. Thoughts, anyone? Thanks, Jason _______________________________________________ Catalyst-dev mailing list Catalyst-dev[at]lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
|