stevieb has asked for the wisdom of the Perl Monks concerning the following question:

update: Solved in Re: Default DB connection details not found: Plack::Test & Dancer2./update

I'm beginning to write my tests for my Dancer2 application. It uses Dancer2::Plugin::Database. It works perfectly fine when running with perl or plackup from the command line, but when I try to execute the following sample/example test, it gives the below error. I just started with Plack::Test, so I'm hoping I'm missing something obvious that I haven't spotted yet. Can those who have experience with webapps have a quick look to see if I'm missing anything glaring?

[App::EnvUI:30727] error @2016-09-30 10:44:11> Asked for default conne +ction (no name given) but no default connection details found in conf +ig in /usr/local/share/perl/5.18.2/Dancer2/Plugin.pm l. 526 Can't get a database connection without settings supplied! Please check you've supplied settings in config as per the Dancer::Plu +gin::Database documentation at /usr/local/share/perl/5.18.2/Dancer/Pl +ugin/Database/Core.pm line 206. Compilation failed in require at t/base.t line 4. BEGIN failed--compilation aborted at t/base.t line 4.

Code:

use strict; use warnings; use App::EnvUI; use HTTP::Request::Common; use Plack::Test; use Test::More; my $test = Plack::Test->create( App::EnvUI->to_app ); subtest 'Sample test' => sub { my $res = $test->request( GET '/' ); ok( $res->is_success, 'Successful request' ); is( $res->content, '{}', 'Empty response back' ); }; done_testing();

My configuration file, config.yml, per the docs (which I know works fine in normal run mode):

plugins: Database: driver: SQLite database: 'db/envui.db' dbi_params: RaiseError: 1 AutoCommit: 1

Replies are listed 'Best First'.
Re: Default DB connection details not found: Plack::Test & Dancer2
by stevieb (Canon) on Oct 01, 2016 at 14:13 UTC

    Figured out the problem...

    I had actually installed my app library into @INC as App::EnvUI, and in my test file, it was loading that one. In that path, the library was obviously not able to find a config file relative to its location.

    If I hadn't of actually installed the module into the system, I would have gotten a Can't locate App/EnvUI.pm in @INC, instead, it was loading the @INC file, complaining about no DB info, as it couldn't read a config file.

    The answer was to add:

    use FindBin; use lib "$FindBin::Bin/../lib";

    To the top of the test file, prior to use App::EnvUI;. That forced the test file to load the application library that's relative to itself, in the application dir structure, instead of the one in @INC, and of course, it knew exactly where to grab the config file from.

    So, it was my fault. Because Dancer2 doesn't require a config file, it won't error out if it can't find one, which led to the confusion as to what was going on.

    In the end, I figured out that no config file was loaded by putting a print Dumper $dsl; on line 514 of Dancer2::Plugin. In the test run, the config_file directive was an empty array ref, but in the normal run, it had the proper config file listed as an element in the aref. I realized at that time that it was the environment that was wrong, not any code.

Re: Default DB connection details not found: Plack::Test & Dancer2 (dump debug dancer configuration)
by Anonymous Monk on Sep 30, 2016 at 21:49 UTC

      Thanks anonymonk,

      I'm going to use my IDE (intellij) to follow through the whole code-flow process for both a standard run and a test run, and figure out exactly why this is happening (probably tonight or tomorrow morning). This'll allow me to pinpoint the areas I need to pepper code with print and possibly caller() statements to figure out exactly what config is being used (or attempting to be used).