From 916fe0e25d89452a80dac4535cc41172b6ebb8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstro=CC=88m?= <erik@erlang.ninja> Date: Tue, 15 Dec 2015 16:41:25 +0100 Subject: [PATCH] Added function to set application config from OS Env --- src/tsuru_application.erl | 5 ++++- test/tsuru_application_test.erl | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tsuru_application.erl b/src/tsuru_application.erl index 743b8eb..06514d3 100644 --- a/src/tsuru_application.erl +++ b/src/tsuru_application.erl @@ -2,7 +2,10 @@ -author("erikh"). %% API --export([get_os_env/1]). +-export([set_env/1, get_os_env/1]). + +set_env(Application) -> + [{application:set_env(Application, Name, Value, [{timeout, infinity}, {persistent, true}]), {Name, Value}} || {Name, Value} <- get_os_env(Application)]. get_os_env(Application) -> Pattern = string:to_upper(atom_to_list(Application)) ++ "_(.+)=(.+)", diff --git a/test/tsuru_application_test.erl b/test/tsuru_application_test.erl index 0af7f87..deb8b63 100644 --- a/test/tsuru_application_test.erl +++ b/test/tsuru_application_test.erl @@ -8,9 +8,9 @@ get_os_env_test() -> os:putenv("TEST_NON_EVAL", "/1/2/3"), os:putenv("TEST_STRING", "\"/1/2/3\""), os:putenv("TEST_ATOM", "'/1/2/3'"), - ?assertEqual(tsuru_application:get_os_env(test), [ - {atom, '/1/2/3'}, - {non_eval, "/1/2/3"}, - {number, 123}, - {string, "/1/2/3"} + ?assertEqual(tsuru_application:set_env(test), [ + {ok, {atom, '/1/2/3'}}, + {ok, {non_eval, "/1/2/3"}}, + {ok, {number, 123}}, + {ok, {string, "/1/2/3"}} ]). -- GitLab