I have a Dancer2 app.
I want to test it properly against a database.
For every test run I create a new database and a new empty schema (PostgreSQL).
My new database has a random name (e.g. app_123abc) and at the end of the test I drop the database.

How can I change the Dancer2 app configuration during the test run, or before I do my $test = Plack::Test->create( $app );?
As it is, is just loads the config files for development. I want to provide my own configuration programmatically. Creating files in the current directory is not an option.

I have tried
config->{'my_stuff'} = \%my_stuff
set 'my_stuff' => \%my_stuff but Dancer2 doesn't seems to pick it up or it gets overwritten later by the config from the files.

Update:

Example

#!/perl ## no critic (Modules::ProhibitMultiplePackages) use strict; use warnings; use 5.014; # JSON::PP included in CORE. package ConfigChangeTest; use Dancer2; set serializer => 'JSON'; get qr{/info}msx => sub { return { appname => config->{'appname'}, }; }; package main; use Test2::V0 -srand => time, qw(:DEFAULT); use Plack::Test; use HTTP::Request; use JSON; use Dancer2; my $appname = 'ConfigChangeTest'; set appname => $appname; my $test = Plack::Test->create( ConfigChangeTest->to_app ); my $req = HTTP::Request->new( GET => '/api/1/info' ); my $res = $test->request( $req ); ok( $res->is_success, 'Is success' ); # Fails! # appname is the one set in the file `environments/development.yml` or + file `config.yml`. is( decode_json $res->content, { appname => $appname, }, 'Is right con +tent' ); done_testing;


In reply to Dancer2: Create a configuration for testing by mikkoi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.