瀏覽代碼

adding config tests

Daniel Moore 11 年之前
父節點
當前提交
a581e07b3e
共有 2 個文件被更改,包括 41 次插入2 次删除
  1. 2 2
      rebar.config
  2. 39 0
      test/config_tests.erl

+ 2 - 2
rebar.config

@@ -1,6 +1,6 @@
 %%-*- mode: erlang -*-
 {deps, [
-%  {meck, "0.7.1", {git, "https://github.com/eproxus/meck.git", {tag, "0.7.1"}}}
+  {meck, "0.8.1", {git, "https://github.com/eproxus/meck.git", {tag, "0.8.1"}}}
 ]}.
 
-{lib_dirs,["/usr/local/lib/couchdb/erlang/lib/"]}.
+{lib_dirs,["/usr/local/Cellar/couchdb/1.4.0/lib/couchdb/erlang/lib/"]}.

+ 39 - 0
test/config_tests.erl

@@ -0,0 +1,39 @@
+-module(config_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+-import(ldap_auth_config, [get_config/1]).
+
+found_1_test_() -> run([
+  ?_assertEqual(get_config(["foo"]), ["oof"]),
+  ?_assertEqual(get_config(["bar"]), ["rab"])
+]).
+
+not_found_1_test_() -> run([
+  ?_assertThrow({config_key_not_found, _}, get_config(["does_not_exist"]))
+]).
+
+found_2_test_() -> run([
+  ?_assertEqual(get_config(["foo", "bar"]), ["oof", "rab"]),
+  ?_assertEqual(get_config(["bar", "foo"]), ["rab", "oof"])
+]).
+
+not_found_2_test_() -> run([
+  ?_assertThrow({config_key_not_found, _}, get_config(["does_not_exist", "foo", "bar"])),
+  ?_assertThrow({config_key_not_found, _}, get_config(["foo", "does_not_exist", "bar"])),
+  ?_assertThrow({config_key_not_found, _}, get_config(["foo", "bar", "does_not_exist"]))
+]).
+
+run(Tests) ->
+  {
+    setup,
+    fun () ->
+      meck:new(couch_config),
+      meck:expect(couch_config, get,
+        fun ("ldap_auth", "foo", _) -> "oof";
+            ("ldap_auth", "bar", _) -> "rab";
+            ("ldap_auth", _, NotFound) -> NotFound
+        end)
+    end,
+    fun (_) -> meck:unload(couch_config) end,
+    fun (_) -> Tests end
+  }.