How to select a specific environment when I do "make test"
Hi, I want to switch to "testing" environment when I call "make test". In fact generally I need 3 environments. Production, Development and Testing. Production, should be use directly from plackup or apache. Development, during dev process, And Testing, when I call "make test", it create a db test, load everything like fixture, and don't mess up development environment. Any idea ? I can do DANCER_ENVIRONMENT=test perl Makefile.PL DANCER_ENVIRONMENT=test make test But is they a better way to do this ?
Well, in fact DANCER_ENVIRONMENT is not use with Dancer::Test; 2011/3/27 Geistteufel <geistteufel@yahoo.fr>:
Hi, I want to switch to "testing" environment when I call "make test".
In fact generally I need 3 environments.
Production, Development and Testing.
Production, should be use directly from plackup or apache.
Development, during dev process,
And Testing, when I call "make test", it create a db test, load everything like fixture, and don't mess up development environment.
Any idea ?
I can do
DANCER_ENVIRONMENT=test perl Makefile.PL DANCER_ENVIRONMENT=test make test
But is they a better way to do this ?
On Sun, Mar 27, 2011 at 6:56 PM, Geistteufel <geistteufel@yahoo.fr> wrote:
Well, in fact DANCER_ENVIRONMENT is not use with Dancer::Test;
2011/3/27 Geistteufel <geistteufel@yahoo.fr>:
Hi, I want to switch to "testing" environment when I call "make test".
If Dancer::Test does not respect DANCER_ENVIRONMENT, it'd be best to open an issue regarding that. You can always do set environment => 'mine'; in the testing code.
My preference should be to set the environment in the Makefile.PL only when I do "make test". It's better that doing this everywhere. I will try to look in the Dancer core code to try to find how Dancer use this env. Because it only work when I can bin/app.pl, I think perhaps I need to use Dancer::Config first, not so sure, I take a look. Le 27 mars 2011 à 19:00, sawyer x a écrit :
On Sun, Mar 27, 2011 at 6:56 PM, Geistteufel <geistteufel@yahoo.fr> wrote: Well, in fact DANCER_ENVIRONMENT is not use with Dancer::Test;
2011/3/27 Geistteufel <geistteufel@yahoo.fr>:
Hi, I want to switch to "testing" environment when I call "make test".
If Dancer::Test does not respect DANCER_ENVIRONMENT, it'd be best to open an issue regarding that.
You can always do set environment => 'mine'; in the testing code.
On Sun, Mar 27, 2011 at 7:05 PM, Geistteufel <geistteufel@yahoo.fr> wrote:
My preference should be to set the environment in the Makefile.PL only when I do "make test". It's better that doing this everywhere.
That's also an option.
I don't know how to do it, Look at these code : use url; use Dancer::Test; route_exists [ GET => '/' ], 'a route'; #It crash, because it try to load development environment and my server is down for testing purpose So I want to add environment "testing" I do that : use Dancer; set environment => "testing"; use Dancer::Config; Dancer::Config->load; And then I redo the same code, It just doesn't work. It doesn't load the "testing" file. And keep crashing on the same port. The only differrence is in the Redis conf : #config.yml plugins: Redis: server: '127.0.0.1:6379' debug: 0 #environments/testing.yml plugins: Redis: server: '127.0.0.1:16379' debug: 0 Is they an easy way to set this, even in all testing file (I can add an init in my "t" directory, to do it). Le 27 mars 2011 à 19:07, sawyer x a écrit :
On Sun, Mar 27, 2011 at 7:05 PM, Geistteufel <geistteufel@yahoo.fr> wrote: My preference should be to set the environment in the Makefile.PL only when I do "make test". It's better that doing this everywhere.
That's also an option.
I have try this way too, but doesn't work : #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 2; # the order is important use url; Dancer::Config::setting({environment => 'testing'}); Dancer::Config->load; use Dancer::Test; route_exists [GET => '/'], 'a route handler is defined for /'; response_status_is ['GET' => '/'], 200, 'response status is 200 for /'; Le 27 mars 2011 à 19:52, Geistteufel a écrit :
I don't know how to do it,
Look at these code :
use url; use Dancer::Test;
route_exists [ GET => '/' ], 'a route';
#It crash, because it try to load development environment and my server is down for testing purpose
So I want to add environment "testing"
I do that :
use Dancer; set environment => "testing"; use Dancer::Config; Dancer::Config->load;
And then I redo the same code,
It just doesn't work. It doesn't load the "testing" file. And keep crashing on the same port.
The only differrence is in the Redis conf :
#config.yml plugins: Redis: server: '127.0.0.1:6379' debug: 0
#environments/testing.yml plugins: Redis: server: '127.0.0.1:16379' debug: 0
Is they an easy way to set this, even in all testing file (I can add an init in my "t" directory, to do it).
Le 27 mars 2011 à 19:07, sawyer x a écrit :
On Sun, Mar 27, 2011 at 7:05 PM, Geistteufel <geistteufel@yahoo.fr> wrote: My preference should be to set the environment in the Makefile.PL only when I do "make test". It's better that doing this everywhere.
That's also an option.
I have post the issue : https://github.com/sukria/Dancer/issues/427 If anyone has an idea. It could help me test my apps :) Le 27 mars 2011 à 20:00, Geistteufel a écrit :
I have try this way too, but doesn't work :
#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 2;
# the order is important use url; Dancer::Config::setting({environment => 'testing'}); Dancer::Config->load; use Dancer::Test;
route_exists [GET => '/'], 'a route handler is defined for /'; response_status_is ['GET' => '/'], 200, 'response status is 200 for /';
Le 27 mars 2011 à 19:52, Geistteufel a écrit :
I don't know how to do it,
Look at these code :
use url; use Dancer::Test;
route_exists [ GET => '/' ], 'a route';
#It crash, because it try to load development environment and my server is down for testing purpose
So I want to add environment "testing"
I do that :
use Dancer; set environment => "testing"; use Dancer::Config; Dancer::Config->load;
And then I redo the same code,
It just doesn't work. It doesn't load the "testing" file. And keep crashing on the same port.
The only differrence is in the Redis conf :
#config.yml plugins: Redis: server: '127.0.0.1:6379' debug: 0
#environments/testing.yml plugins: Redis: server: '127.0.0.1:16379' debug: 0
Is they an easy way to set this, even in all testing file (I can add an init in my "t" directory, to do it).
Le 27 mars 2011 à 19:07, sawyer x a écrit :
On Sun, Mar 27, 2011 at 7:05 PM, Geistteufel <geistteufel@yahoo.fr> wrote: My preference should be to set the environment in the Makefile.PL only when I do "make test". It's better that doing this everywhere.
That's also an option.
I think it's the Dancer::Plugin::Redis which is not load properly, I will try to test the content of config to check if anythink is setted properly, and try a patch on the plugin, to see if something change. The only think I know is that plugin read properly the main config.yml, but I have a doubt concerning the environments files. The get plugin setting is set before the register, which can cause a bad load. I will try to figure it out quickly. 2011/3/27 Geistteufel <geistteufel@yahoo.fr>:
I have post the issue : https://github.com/sukria/Dancer/issues/427 If anyone has an idea. It could help me test my apps :)
Le 27 mars 2011 à 20:00, Geistteufel a écrit :
I have try this way too, but doesn't work : #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 2; # the order is important use url; Dancer::Config::setting({environment => 'testing'}); Dancer::Config->load; use Dancer::Test; route_exists [GET => '/'], 'a route handler is defined for /'; response_status_is ['GET' => '/'], 200, 'response status is 200 for /';
Le 27 mars 2011 à 19:52, Geistteufel a écrit :
I don't know how to do it, Look at these code : use url; use Dancer::Test; route_exists [ GET => '/' ], 'a route'; #It crash, because it try to load development environment and my server is down for testing purpose So I want to add environment "testing" I do that : use Dancer; set environment => "testing"; use Dancer::Config; Dancer::Config->load; And then I redo the same code, It just doesn't work. It doesn't load the "testing" file. And keep crashing on the same port. The only differrence is in the Redis conf : #config.yml plugins: Redis: server: '127.0.0.1:6379' debug: 0 #environments/testing.yml plugins: Redis: server: '127.0.0.1:16379' debug: 0 Is they an easy way to set this, even in all testing file (I can add an init in my "t" directory, to do it). Le 27 mars 2011 à 19:07, sawyer x a écrit :
On Sun, Mar 27, 2011 at 7:05 PM, Geistteufel <geistteufel@yahoo.fr> wrote:
My preference should be to set the environment in the Makefile.PL only when I do "make test". It's better that doing this everywhere.
That's also an option.
Hey I looked into it, and apparently Dancer::Test *does* check for the environment: in file: use Dancer::Test; use Dancer::Config; print Dancer::Config::setting('mykey'), "\n"; -- If I run it as: DANCER_ENVIRONMENT=test perl -Ilib file.pl ... it does print the value of the key 'mykey' configured in test.yml inside 'environments'. So there is no problem there.
Everything works if I run bin/app.pl, but no way under test Could you take a look at there : https://github.com/geistteufel/Dancer-Plugin-Redis/blob/master/lib/Dancer/Pl... I don't get at all what is the problem of this plugin ??? In fact, I have try to Dumper settings, under the "register" function, and surprise : nothing at all. So Redis take only default params, which is not the test. plugin_settings seems to give nothing at all. I do that : use Dancer; Dancer::set environment => 'testing'; Dancer::Config->load; use Dancer::Plugin::Redis; And die Dumper $settings in the module, give me $VAR1 = {} ... Any idea ? Le 28 mars 2011 à 13:12, sawyer x a écrit :
Hey
I looked into it, and apparently Dancer::Test does check for the environment:
in file: use Dancer::Test; use Dancer::Config;
print Dancer::Config::setting('mykey'), "\n"; --
If I run it as: DANCER_ENVIRONMENT=test perl -Ilib file.pl ... it does print the value of the key 'mykey' configured in test.yml inside 'environments'.
So there is no problem there.
Yeah ! I have found a way ! It's really not easy !!! So, here the code : use url; Dancer::set environment => 'testing'; Dancer::Config->load; use Dancer::Test; Never ever do a use Dancer when I use my module which use Dancer. And so, I have fix the Redis plugin : I do my $settings; register_redis => sub { $settings ||= plugin_setting; ... } Ok not it's ok, the test can run ! I send the patch to the author. Le 28 mars 2011 à 23:17, Geistteufel a écrit :
Everything works if I run bin/app.pl, but no way under test
Could you take a look at there :
https://github.com/geistteufel/Dancer-Plugin-Redis/blob/master/lib/Dancer/Pl...
I don't get at all what is the problem of this plugin ???
In fact, I have try to Dumper settings, under the "register" function, and surprise : nothing at all. So Redis take only default params, which is not the test.
plugin_settings seems to give nothing at all.
I do that :
use Dancer; Dancer::set environment => 'testing'; Dancer::Config->load; use Dancer::Plugin::Redis;
And die Dumper $settings in the module, give me
$VAR1 = {}
...
Any idea ?
Le 28 mars 2011 à 13:12, sawyer x a écrit :
Hey
I looked into it, and apparently Dancer::Test does check for the environment:
in file: use Dancer::Test; use Dancer::Config;
print Dancer::Config::setting('mykey'), "\n"; --
If I run it as: DANCER_ENVIRONMENT=test perl -Ilib file.pl ... it does print the value of the key 'mykey' configured in test.yml inside 'environments'.
So there is no problem there.
participants (2)
-
Geistteufel -
sawyer x