diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-12-07 11:38:38 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-12-07 11:38:38 -0600 |
commit | 67f6faef462e1b1327596dc2228c28c3deeaba0c (patch) | |
tree | 62736158776e23c2b2e4e1b73882634f535b863c | |
parent | 1e0cb25b0d708249bc266728d486f6b3235db19b (diff) | |
download | couchdb-67f6faef462e1b1327596dc2228c28c3deeaba0c.tar.gz |
Update the context in place for setup
Turns out that with multiple setup functions the same context is piped
through each definition. Thus we'll always want to update in place
rather than creating empty contexts which possibly removes settings made
in previous setup or setup_all invocations.
-rw-r--r-- | elixir_suite/test/test_helper.exs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/elixir_suite/test/test_helper.exs b/elixir_suite/test/test_helper.exs index ecd88e5bf..cef7d13c0 100644 --- a/elixir_suite/test/test_helper.exs +++ b/elixir_suite/test/test_helper.exs @@ -15,31 +15,36 @@ defmodule CouchTestCase do use ExUnit.Case setup context do - {:ok, db_context} = set_db_context(context) - {:ok, cfg_context} = set_config_context(context) - {:ok, db_context ++ cfg_context} + setup_funs = [ + &set_db_context/1, + &set_config_context/1 + ] + context = Enum.reduce(setup_funs, context, fn setup_fun, acc -> + setup_fun.(acc) + end) + {:ok, context} end def set_db_context(context) do - db_name = if context[:with_db] != nil or context[:with_db_name] != nil do - if context[:with_db] != nil and context[:with_db] != true do - context[:with_db] - else - case context[:with_db_name] do - nil -> random_db_name() - true -> random_db_name() - name -> name - end - end + context = case context do + %{:with_db_name => true} -> + Map.put(context, :db_name, random_db_name()) + %{:with_db_name => db_name} when is_binary(db_name) -> + Map.put(context, :db_name, db_name) + %{:with_db => true} -> + Map.put(context, :db_name, random_db_name()) + %{:with_db => db_name} when is_binary(db_name) -> + Map.put(context, :db_name, db_name) + _ -> + context end - if context[:with_db] != nil do - {:ok, _} = create_db(db_name) - - on_exit(fn -> delete_db(db_name) end) + if Map.has_key? context, :with_db do + {:ok, _} = create_db(context[:db_name]) + on_exit(fn -> delete_db(context[:db_name]) end) end - {:ok, db_name: db_name} + context end def set_config_context(context) do @@ -48,7 +53,7 @@ defmodule CouchTestCase do set_config(cfg) end) end - {:ok, []} + context end def random_db_name do |