From 3614cefaf8410876797401dc5146808ced1e1430 Mon Sep 17 00:00:00 2001 From: Zemuldo Date: Tue, 24 Oct 2023 14:18:44 +0300 Subject: [PATCH] fix tests --- lib/ex_secrets.ex | 6 +- test/ex_secrets_test.exs | 109 +++++++++++++------------ test/support/fixtures/dot_env_test.env | 1 + 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/lib/ex_secrets.ex b/lib/ex_secrets.ex index fa17ceb..b9758f1 100644 --- a/lib/ex_secrets.ex +++ b/lib/ex_secrets.ex @@ -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 """ diff --git a/test/ex_secrets_test.exs b/test/ex_secrets_test.exs index 895329c..0caf7d3 100644 --- a/test/ex_secrets_test.exs +++ b/test/ex_secrets_test.exs @@ -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 diff --git a/test/support/fixtures/dot_env_test.env b/test/support/fixtures/dot_env_test.env index 11fa790..388f3ef 100644 --- a/test/support/fixtures/dot_env_test.env +++ b/test/support/fixtures/dot_env_test.env @@ -1,2 +1,3 @@ JAVA=SCRIPT ER=LANG +DEVS=ROCKS