Hi Nobbz,
I don’t think I can really…I have a “dbms” module that calls application:get_env/2 and the results is always undefined
except when running normally from rebar shell
.
I have been driven to the edge of the maelstrom by commontest today to be honest.
Ironically even running under rebar eunit
is doing the same thing now…must have got out of bed the wrong way or something.
foo_test() ->
Cfg = application:get_env(scofblog, dbms),
?assertNotMatch(Cfg, undefined).
running under rebar3 shell
however it’s fine
1> application:get_env(scofblog, dbms).
{ok,[{server,"localhost"},
{database,"scofblog"},
{username,"sean"},
{password,"???????"},
{blogroot,"/home/sean/Documents/code/haskell/monadic-warrior-hakyll-site/posts"},
{blogspec,"*.md"}]}
and he is my rebar.config
file for good measure
{erl_opts, [debug_info]}.
{cover_enabled, true}.
{deps, [
{epgsql, {git, "https://github.com/epgsql/epgsql.git"}, {tag, "4.4.0"}},
{cowboy, {git, "https://github.com/ninenines/cowboy.git"}, {tag, "2.9.1"}},
{jsone, {git, "https://github.com/sile/jsone.git"}, {tag, "v0.3.3"}},
{gen_smtp, {git, "https://github.com/gen-smtp/gen_smtp.git"}, {tag, "0.15.0"}}
]}.
{profiles,
[
{test,
[
{deps, [meck]}
]}
]}.
{shell, [
% {config, "config/sys.config"},
{apps, [scofblog]}
]}.
might as well throw in the failed suite as well
-module(dbms_SUITE).
-export([all/0,
init_per_suite/1,
init_per_testcase/2,
end_per_suite/1,
end_per_testcase/2
]).
-export([can_insert_row/1, can_insert_new_topic/1]).
-include("./src/scofblog_common.hrl").
all() -> [can_insert_new_topic, can_insert_row].
init_per_suite(_InitConfig) ->
%% there MUST be a "rebar3" way of doing this, I read the epgsql
%% test code for ages but really I just need to get this project
%% finished for now!
{ok, [{application, scofblog, Props}]}
= file:consult("../../../../src/scofblog.app.src"),
Env = ?prop(env, Props),
Dbms = ?prop(dbms, Env),
%% independant database connection
{ok, C} =
epgsql:connect(
?prop(server, Dbms),
?prop(username, Dbms),
?prop(password, Dbms),
#{database=> "scofblog_test"}
),
ct:pal("DBMS connected: ~w~n", [C]),
[{conn, C}].
end_per_suite(Config) ->
Conn = ?prop(conn, Config),
epgsql:close(Conn),
ct:pal("end_per_suite: DB Closeed OK~n",[]).
%% TEST init / end
init_per_testcase(Test, Config) ->
ct:pal("init_per_testcase: for ~s~n", [Test]),
C = ?prop(conn, Config),
ct:pal("init_per_testcase: C: ~w~n", [C]),
%T1 = epgsql:squery(C, "truncate comment cascade"),
%T2 = epgsql:squery(C, "truncate author cascade"),
%T3 = epgsql:squery(C, "truncate topic cascade"),
%ct:pal("T1: ~w~n", [T1]),
%ct:pal("T2: ~w~n", [T2]),
%ct:pal("T3: ~w~n", [T3]),
Config.
end_per_testcase(Test, _Config) ->
ct:pal("end_per_testcase: ~s~n", [Test]).
can_insert_new_topic(_Cfg) ->
{ok, TC} = test_connect(),
epgsql:close(TC).
can_insert_row(Config) ->
C = ?prop(conn, Config),
ct:pal("TEST: can_insert_row: config: ~w~n", [C]),
1 =:= 2.
test_connect() ->
dbms:connect("scofblog_test").