config_tests.erl 1.1 KB

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