Skip to content

Commit

Permalink
test that any configured config_module is called at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
peburrows committed Feb 17, 2018
1 parent e13ec5f commit 49685b5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/goth/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ defmodule Goth.Config do
# and pass it along to each config function

def init(:ok) do
{:ok, dynamic_config} = config_mod_init(Application.get_all_env(:goth))
{:ok, dynamic_config} =
Application.get_all_env(:goth)
|> config_mod_init

config = from_json(dynamic_config) ||
from_config(dynamic_config) ||
Expand All @@ -52,8 +54,7 @@ defmodule Goth.Config do
{:ok, config}
end

# this requires
def config_mod_init(config) do
defp config_mod_init(config) do
case Keyword.get(config, :config_module) do
nil -> {:ok, config}
mod ->
Expand Down
4 changes: 4 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Goth.Mixfile do
version: "0.7.2",
description: description(),
package: package(),
elixirc_paths: elixirc_paths(Mix.env),
elixir: "~> 1.4",
deps: deps()]
end
Expand All @@ -17,6 +18,9 @@ defmodule Goth.Mixfile do
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

defp deps do
[{:json_web_token, "~> 0.2.10"},
{:httpoison, "~> 0.11"},
Expand Down
12 changes: 12 additions & 0 deletions test/goth/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,16 @@ defmodule Goth.ConfigTest do
Application.stop(:goth)
Application.start(:goth)
end

test "the config_module is allowed to override config" do
Application.put_env(:goth, :config_module, Goth.TestConfigMod)
Application.stop(:goth)

Application.start(:goth)
assert {:ok, :val} == Goth.Config.get(:actor_email)

Application.delete_env(:goth, :config_module)
Application.stop(:goth)
Application.start(:goth)
end
end
7 changes: 7 additions & 0 deletions test/support/test_config_mod.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Goth.TestConfigMod do
use Goth.Config

def init(config) do
{:ok, Keyword.put(config, :actor_email, :val)}
end
end

0 comments on commit 49685b5

Please sign in to comment.