config_tests.erl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -module(config_tests).
  2. -include("couch_db.hrl").
  3. -include_lib("eunit/include/eunit.hrl").
  4. -import(ldap_auth_config, [get_config/1]).
  5. found_1_test_() -> run([
  6. ?_assertEqual(get_config(["foo"]), ["oof"]),
  7. ?_assertEqual(get_config(["bar"]), ["rab"])
  8. ]).
  9. not_found_1_test_() -> run([
  10. ?_assertThrow({config_key_not_found, _}, get_config(["does_not_exist"]))
  11. ]).
  12. found_2_test_() -> run([
  13. ?_assertEqual(get_config(["foo", "bar"]), ["oof", "rab"]),
  14. ?_assertEqual(get_config(["bar", "foo"]), ["rab", "oof"])
  15. ]).
  16. not_found_2_test_() -> run([
  17. ?_assertThrow({config_key_not_found, _}, get_config(["does_not_exist", "foo", "bar"])),
  18. ?_assertThrow({config_key_not_found, _}, get_config(["foo", "does_not_exist", "bar"])),
  19. ?_assertThrow({config_key_not_found, _}, get_config(["foo", "bar", "does_not_exist"]))
  20. ]).
  21. run(Tests) ->
  22. {
  23. setup,
  24. fun () ->
  25. meck:new(couch_config, [non_strict]),
  26. meck:expect(couch_config, get,
  27. fun ("ldap_auth", "foo", _) -> "oof";
  28. ("ldap_auth", "bar", _) -> "rab";
  29. ("ldap_auth", _, NotFound) -> NotFound
  30. end)
  31. end,
  32. fun (_) -> meck:unload(couch_config) end,
  33. fun (_) -> Tests end
  34. }.