Paths in Common Test app.config

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Paths in Common Test app.config

Roger Lipscombe-2
It appears that Common Test runs my suites from an arbitrary current
directory (somewhere under "logs").

This means that I cannot reliably use relative paths in my
'app.config' file. For example, I can't easily configure the paths to
my TLS certificate files without monkeying around with the current
working directory before calling application:ensure_started(my_app).

Currently, I've got some code that walks back up the directory tree --
with file:set_cwd("..") -- until it finds a marker file (currently
"rebar.config"), and then I specify the paths relative to this.

This seems ... brittle.

What do others do to deal with this?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

PAILLEAU Eric
Hi,

Use config to set external things available 

http://erlang.org/doc/apps/common_test/config_file_chapter.html#id84119

Regards



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

PAILLEAU Eric
See also

http://erlang.org/doc/apps/common_test/write_test_chapter.html#id78070

To store your data needed by your tests.
Regards 


Le 17 nov. 2017 8:50 PM, Éric Pailleau <[hidden email]> a écrit :
Hi,

Use config to set external things available 

http://erlang.org/doc/apps/common_test/config_file_chapter.html#id84119

Regards




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

Roger Lipscombe-2
In reply to this post by PAILLEAU Eric
That doesn't seem to be what I want. Let me clarify...

I run my tests with "rebar3 ct", and I have an app.config file
containing the following (for example):

[{my_app, [{cert_path, "relative/path/to/cert.crt"}]}].

It can't be an absolute path, because the project might be checked out
in different locations on different machines.

In my suite, I run my application as follows:

application:ensure_started(my_app)

I have, in my application:

CertPath = application:get_env(my_app, cert_path)

But, when "rebar3 ct" runs my test, the current directory is set to
somewhere like "/home/roger/Projects/my_app/_build/test/logs/ct_run.nonode@nohost.2017-11-17_19.57.30/",
which means that these relative paths are wrong, and my application
doesn't start correctly.

When using rebar3, or CT itself, how do I control the initial working
directory for the suite, so that I can put my cert files in a sensible
location, and refer to them with relative paths?

I'm considering using file:set_cwd(?config(data_dir, Config) ++ "/..")
in each suite's init_per_testcase, but that feels awkward.

To reiterate: I'm not trying to configure the test. I'm trying to
configure the application under test.

On 17 November 2017 at 19:50, Éric Pailleau <[hidden email]> wrote:
> Hi,
>
> Use config to set external things available
>
> http://erlang.org/doc/apps/common_test/config_file_chapter.html#id84119
>
> Regards
>
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

PAILLEAU Eric
In reply to this post by PAILLEAU Eric
I'm afraid you have to set pwd at each case from this note: 

Note

Do not depend on the current working directory for reading and writing data files, as this is not portable. All scratch files are to be written in the priv_dir and all data files are to be located in data_dir. Also, the Common Test server sets the current working directory to the test case log directory at the start of every case.



Le 17 nov. 2017 8:58 PM, Éric Pailleau <[hidden email]> a écrit :
See also

http://erlang.org/doc/apps/common_test/write_test_chapter.html#id78070

To store your data needed by your tests.
Regards 


Le 17 nov. 2017 8:50 PM, Éric Pailleau <eric.pailleau@wanadoo.fr> a écrit :
Hi,

Use config to set external things available 

http://erlang.org/doc/apps/common_test/config_file_chapter.html#id84119

Regards





_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

Fred Hebert-2
In reply to this post by Roger Lipscombe-2
On 11/17, Roger Lipscombe wrote:
>It appears that Common Test runs my suites from an arbitrary current
>directory (somewhere under "logs").
>

Yes, this allows any writes and reads taking place to be effectively in
an isolated context for the test. This is generally a good thing since
you can get per test run disk output to go look at how things are doing,
what was created on disk and what was modified.

>This means that I cannot reliably use relative paths in my
>'app.config' file. For example, I can't easily configure the paths to
>my TLS certificate files without monkeying around with the current
>working directory before calling application:ensure_started(my_app).
>
>Currently, I've got some code that walks back up the directory tree --
>with file:set_cwd("..") -- until it finds a marker file (currently
>"rebar.config"), and then I specify the paths relative to this.
>
>This seems ... brittle.
>
>What do others do to deal with this?

It *is* brittle. I would try to avoid working with current working
directory settings at pretty much all costs.

The safe thing to do would be to give the certificates and files
required in the data_dir for Common Test. This is a directory in test/
with the name your_SUITE_data/. In init_per_suite, you can then set the
application env value:

    init_per_suite(Config) ->
        application:load(your_app),
        Cert = filename:join([?config(data_dir, Config), "some_cert.crt"]),
        applicatoin:set_env(your_app, certfile, Cert),
        Config.

The test can then proceed as usual. If you really want to have the
ability to 'carry' a file at all times with an app, that tends to be
done through the priv/ directory of that application.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

Roger Lipscombe-2
On 17 November 2017 at 23:21, Fred Hebert <[hidden email]> wrote:
> The safe thing to do would be to give the certificates and files required in
> the data_dir for Common Test. This is a directory in test/ with the name
> your_SUITE_data/. In init_per_suite, you can then set the application env
> value:

My problem is that I have several configuration settings that require
filenames, at various levels of nesting. I also kinda wanted to share
the cert files between all of the suites for the application.

>    init_per_suite(Config) ->
>        application:load(your_app),
>        Cert = filename:join([?config(data_dir, Config), "some_cert.crt"]),
>        applicatoin:set_env(your_app, certfile, Cert),
>        Config.

It occurs that it might be possible to do something in a CT hook: it
could recursively look for string values and do $VAR replacements on
them from environment variables, or from that CT hook's options...

> The test can then proceed as usual. If you really want to have the ability
> to 'carry' a file at all times with an app, that tends to be done through
> the priv/ directory of that application.

Sure, but these are explicitly test artifacts; I'm not going to be
keeping the production certificates and keys in the repository
(*those* get installed by, e.g., chef during machine bring-up).
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

PAILLEAU Eric
Did you considered the option of getting thoses data from an online service if not available on disk ?
Either an Erlang node or another app with secured connection ?
This would avoid the need to embed those data for test, and let your production server pick up the data if not available locally.


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Paths in Common Test app.config

Richard A. O'Keefe-2
In reply to this post by Roger Lipscombe-2


On 19/11/17 2:17 AM, Roger Lipscombe wrote:

> My problem is that I have several configuration settings that require
> filenames, at various levels of nesting. I also kinda wanted to share
> the cert files between all of the suites for the application.

Can you put the cert files in a directory of their own and
create symbolic links / aliases / whatever to them in the suites'
data_dirs?

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions