Skip to content

Commit

Permalink
adds tests for reload
Browse files Browse the repository at this point in the history
  • Loading branch information
zemuldo committed Sep 10, 2023
1 parent d7021f5 commit ce34663
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/ex_secrets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ defmodule ExSecrets do
end

def clear_cache(), do: GenServer.cast(Cache, :clear)

def reset() do
providers = ExSecrets.Application.get_providers()

Enum.each(providers, fn provider ->
case Resolver.call(provider) do
{:error, _} -> :ok
provider -> Kernel.apply(provider, :reset, [])
end
end)
end
end
21 changes: 21 additions & 0 deletions test/providers/dot_env_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,25 @@ defmodule ExSecrets.Providers.DotEnvTest do

assert ExSecrets.get("ASD", :dot_env) == "FGH"
end

test "reset" do
Application.put_env(:ex_secrets, :providers, %{
dot_env: %{path: "test/support/fixtures/dot_env_test.env"}
})

{:ok, _} = GenServer.start(ExSecrets.Providers.DotEnv, [])
assert ExSecrets.get("JAVA", :dot_env) == "SCRIPT"

Application.put_env(:ex_secrets, :providers, %{
dot_env: %{path: "test/support/fixtures/dot_env_test_3.env"}
})

ExSecrets.Providers.DotEnv.reset()

assert ExSecrets.get("JAVA", :dot_env) == "SCRIPTT"

Application.put_env(:ex_secrets, :providers, %{
dot_env: %{path: "test/support/fixtures/dot_env_test.env"}
})
end
end
2 changes: 2 additions & 0 deletions test/support/fixtures/dot_env_test_3.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JAVA=SCRIPTT
ER=LANGG

0 comments on commit ce34663

Please sign in to comment.