[erlang-questions] Paths in Common Test app.config

Fred Hebert mononcqc@REDACTED
Sat Nov 18 00:21:30 CET 2017


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.




More information about the erlang-questions mailing list