Discussion:
[erlang-questions] CT and test.config
Roberto Ostinelli
2015-04-23 11:41:44 UTC
Permalink
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.

I'm passing the variable `-config test.config` to ct_run.

However, when I start my app from the Common Test suite `myapp_SUITE.erl`
then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.

How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?

I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool instead.
Please help me stick to Erlang. :)

r.
Loïc Hoguin
2015-04-23 11:53:01 UTC
Permalink
ct_run -erl_args -config test.config
Post by Roberto Ostinelli
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
--
Loïc Hoguin
http://ninenines.eu
Peter Andersson
2015-04-23 12:03:16 UTC
Permalink
Roberto, you can read about -erl_args here:

http://www.erlang.org/doc/man/ct_run.html

The CT flag config is unfortunately named, but we decided to keep the
name and rely on the -erl_args feature. With -erl_args we don't have to
prefix all CT flags in order to avoid possible clashes with erl flags
(now and in the future).

Best,
Peter
Post by Loïc Hoguin
ct_run -erl_args -config test.config
Post by Roberto Ostinelli
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
Roberto Ostinelli
2015-04-23 13:25:13 UTC
Permalink
Thank you for clarifying Peter. That was confusing.
Post by Peter Andersson
http://www.erlang.org/doc/man/ct_run.html
The CT flag config is unfortunately named, but we decided to keep the
name and rely on the -erl_args feature. With -erl_args we don't have to
prefix all CT flags in order to avoid possible clashes with erl flags
(now and in the future).
Best,
Peter
Post by Loïc Hoguin
ct_run -erl_args -config test.config
Post by Roberto Ostinelli
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can,
however,
Post by Loïc Hoguin
Post by Roberto Ostinelli
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
Roberto Ostinelli
2015-04-23 13:24:50 UTC
Permalink
Thank you Loïc, this works (i.e. `myapp` now starts) but now I'm unable to
read this config file in `myapp_SUITE.erl`.

`application:get_env(myapp, mykey)` and `ct:get_config({myapp, mykey})`
both return `undefined`.
Post by Loïc Hoguin
ct_run -erl_args -config test.config
Post by Roberto Ostinelli
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
--
Loïc Hoguin
http://ninenines.eu
Roberto Ostinelli
2015-04-23 13:41:22 UTC
Permalink
My main need is to be able to modify app variables on the fly, to test
different behaviors from CT.

I'm fed up with this so I'm no instead initializing in my CT
`init_per_suite/1` function all the application variables like this:


set_environment_variables() ->
% read config file
ConfigFilePath = filename:join([filename:dirname(code:which(?MODULE)),
"test.config"]),
{ok, [AppsConfig]} = file:consult(ConfigFilePath),
% loop to set variables
F = fun({AppName, AppConfig}) ->
set_environment_for_app(AppName, AppConfig)
end,
lists:foreach(F, AppsConfig).

set_environment_for_app(AppName, AppConfig) ->
F = fun({Key, Val}) ->
application:set_env(AppName, Key, Val)
end,
lists:foreach(F, AppConfig).


If anyone knows a better way, please let me know.

Best,
r.
Post by Roberto Ostinelli
Thank you Loïc, this works (i.e. `myapp` now starts) but now I'm unable to
read this config file in `myapp_SUITE.erl`.
`application:get_env(myapp, mykey)` and `ct:get_config({myapp, mykey})`
both return `undefined`.
Post by Loïc Hoguin
ct_run -erl_args -config test.config
Post by Roberto Ostinelli
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
--
Loïc Hoguin
http://ninenines.eu
Peter Andersson
2015-04-23 13:50:09 UTC
Permalink
Well, if you want the same config file as input to both your application
and to CT:

ct_run -config test.config -erl_args -config test.config

/Peter
Thank you Loïc, this works (i.e. `myapp` now starts) but now I'm
unable to read this config file in `myapp_SUITE.erl`.
`application:get_env(myapp, mykey)` and `ct:get_config({myapp,
mykey})` both return `undefined`.
ct_run -erl_args -config test.config
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test
configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
--
Loïc Hoguin
http://ninenines.eu
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
Roberto Ostinelli
2015-04-23 13:56:43 UTC
Permalink
Unfortunately that doesn't work.

`test.config` for application needs to be a file which encloses a list of
Applications, i.e. [{App1, [App1Config]}, {App2, [App2Config]}].
`test.config` for CT needs to be a file which has individual entries *not*
enclosed in a list, i.e. {App1, [App1Config]}. {App2, [App2Config]}.
Post by Peter Andersson
Well, if you want the same config file as input to both your application
ct_run -config test.config -erl_args -config test.config
/Peter
Thank you Loïc, this works (i.e. `myapp` now starts) but now I'm unable to
read this config file in `myapp_SUITE.erl`.
`application:get_env(myapp, mykey)` and `ct:get_config({myapp, mykey})`
both return `undefined`.
Post by Loïc Hoguin
ct_run -erl_args -config test.config
Post by Roberto Ostinelli
All,
I've got an app `myapp` which uses a standard `sys.config` file.
I'd like to test it using Common Tests, with a test configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because inside the app
`application:get_env(myapp, mykey)` returns `undefined`. I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5 minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
--
Loïc Hoguin
http://ninenines.eu
_______________________________________________
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
Peter Andersson
2015-04-23 14:05:10 UTC
Permalink
True, if you want the same config file as input to both, you need the
"userconfig" feature in Common Test:

http://www.erlang.org/doc/apps/common_test/config_file_chapter.html#id79185
http://www.erlang.org/doc/man/ct_run.html
http://www.erlang.org/doc/man/ct.html#run_test-1

/Peter
Post by Roberto Ostinelli
Unfortunately that doesn't work.
`test.config` for application needs to be a file which encloses a list
of Applications, i.e. [{App1, [App1Config]}, {App2, [App2Config]}].
`test.config` for CT needs to be a file which has individual entries
*not* enclosed in a list, i.e. {App1, [App1Config]}. {App2, [App2Config]}.
Well, if you want the same config file as input to both your
ct_run -config test.config -erl_args -config test.config
/Peter
Post by Roberto Ostinelli
Thank you Loïc, this works (i.e. `myapp` now starts) but now I'm
unable to read this config file in `myapp_SUITE.erl`.
`application:get_env(myapp, mykey)` and `ct:get_config({myapp,
mykey})` both return `undefined`.
ct_run -erl_args -config test.config
All,
I've got an app `myapp` which uses a standard
`sys.config` file.
I'd like to test it using Common Tests, with a test
configuration file.
I'm passing the variable `-config test.config` to ct_run.
However, when I start my app from the Common Test suite
`myapp_SUITE.erl` then the app fails to start because
inside the app
`application:get_env(myapp, mykey)` returns `undefined`.
I can, however,
read this variable with `ct:get_config({myapp, mykey})`.
How am I supposed to use a custom `test.config` file that
is loaded in
ct_run *and* read by the app itself?
I've spent almost a day on this and I'm honestly 5
minutes away from
dropping all this in the dustbin and using an external test tool
instead. Please help me stick to Erlang. :)
r.
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
--
Loïc Hoguin
http://ninenines.eu
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
http://erlang.org/mailman/listinfo/erlang-questions
Continue reading on narkive:
Loading...