Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zemuldo committed Oct 24, 2023
1 parent 586b6dc commit 3614cef
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
6 changes: 2 additions & 4 deletions lib/ex_secrets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ defmodule ExSecrets do
## Examples
iex(1)> Application.put_env(:ex_secrets, :providers, %{dot_env: %{path: "test/support/fixtures/dot_env_test.env"}})
:ok
iex(2)> ExSecrets.get("JAVA", :dot_env)
"SCRIPT"
iex(3)> ExSecrets.get("JAVA")
"SCRIPT"
iex(2)> ExSecrets.get("DEVS", :dot_env)
"ROCKS"
iex(4)> Application.delete_env(:ex_secrets, :providers)
:ok
"""
Expand Down
109 changes: 55 additions & 54 deletions test/ex_secrets_test.exs
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
defmodule ExSecretsTest do
use ExUnit.Case, async: false
doctest ExSecrets

# test "Get FOO - nil" do
# k = "FOO#{:rand.uniform(100)}"
# assert ExSecrets.get(k) == nil
# end
doctest ExSecrets, async: false

# test "Get FOO - BAR" do
# k = "FOO#{:rand.uniform(1000)}"
# System.put_env(k, "BAR")
# assert ExSecrets.get(k) == "BAR"
# System.delete_env(k)
# end
test "Get FOO - nil" do
k = "FOO#{:rand.uniform(100)}"
assert ExSecrets.get(k) == nil
end

# test "Get with Provider FOO - BAR" do
# k = "FOO#{:rand.uniform(1000)}"
# System.put_env(k, "BARR")
# assert ExSecrets.get(k, :system_env) == "BARR"
# System.delete_env(k)
# end
test "Get FOO - BAR" do
k = "FOO#{:rand.uniform(1000)}"
System.put_env(k, "BAR")
assert ExSecrets.get(k) == "BAR"
System.delete_env(k)
end

# test "Get with wring Provider FOOOZ - BARRZ" do
# k = "FOO#{:rand.uniform(1000)}"
# assert ExSecrets.get(k, :abc) == nil
# System.delete_env(k)
# end
test "Get with Provider FOO - BAR" do
k = "FOO#{:rand.uniform(1000)}"
System.put_env(k, "BARR")
assert ExSecrets.get(k, :system_env) == "BARR"
System.delete_env(k)
end

# test "Get with configuration FOO - BAR" do
# k = "FOO#{:rand.uniform(1000)}"
# Application.put_env(:ex_secrets, :providers, %{xyz: %{path: "test"}})
# System.put_env(k, "BARR")
# assert ExSecrets.get(k, :system_env) == "BARR"
# System.delete_env(k)
# Application.delete_env(:ex_secrets, :providers)
# end
test "Get with wring Provider FOOOZ - BARRZ" do
k = "FOO#{:rand.uniform(1000)}"
assert ExSecrets.get(k, :abc) == nil
System.delete_env(k)
end

# test "GET from System env if " do
# k = "FOO#{:rand.uniform(1000)}"
# Application.put_env(:ex_secrets, :providers, %{xyz: %{path: "test"}})
# System.put_env(k, "BARR")
# assert ExSecrets.get(k) == "BARR"
# System.delete_env(k)
# Application.delete_env(:ex_secrets, :providers)
# end
test "Get with configuration FOO - BAR" do
k = "FOO#{:rand.uniform(1000)}"
Application.put_env(:ex_secrets, :providers, %{xyz: %{path: "test"}})
System.put_env(k, "BARR")
assert ExSecrets.get(k, :system_env) == "BARR"
System.delete_env(k)
Application.delete_env(:ex_secrets, :providers)
end

# test "reset" do
# Application.put_env(:ex_secrets, :providers, %{
# dot_env: %{path: "test/support/fixtures/dot_env_test.env"}
# })
test "GET from System env if " do
k = "FOO#{:rand.uniform(1000)}"
Application.put_env(:ex_secrets, :providers, %{xyz: %{path: "test"}})
System.put_env(k, "BARR")
assert ExSecrets.get(k) == "BARR"
System.delete_env(k)
Application.delete_env(:ex_secrets, :providers)
end

# {:ok, _} = GenServer.start(ExSecrets.Providers.DotEnv, [])
# assert ExSecrets.get("JAVA", :dot_env) == "SCRIPT"
test "reset" do
Application.put_env(:ex_secrets, :providers, %{
dot_env: %{path: "test/support/fixtures/dot_env_test.env"}
})

# Application.put_env(:ex_secrets, :providers, %{
# dot_env: %{path: "test/support/fixtures/dot_env_test_3.env"}
# })
{:ok, _} = GenServer.start(ExSecrets.Providers.DotEnv, [])
assert ExSecrets.get("JAVA", :dot_env) == "SCRIPT"

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

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

# Application.put_env(:ex_secrets, :providers, %{
# dot_env: %{path: "test/support/fixtures/dot_env_test.env"}
# })
assert ExSecrets.get("JAVA", :dot_env) == "SCRIPTT"

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

Application.delete_env(:ex_secrets, :providers)
end
end
1 change: 1 addition & 0 deletions test/support/fixtures/dot_env_test.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
JAVA=SCRIPT
ER=LANG
DEVS=ROCKS

0 comments on commit 3614cef

Please sign in to comment.