summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2021-03-31 00:33:38 +0000
committerAdam Kocoloski <kocolosk@apache.org>2021-03-31 00:33:38 +0000
commit1d87feb220a334d3592b8358f36c8a7a39a7c849 (patch)
treeac12d19906b0b93d886dbfbf13e9ba21974e017f
parent1d328be325f97f7fde6991b9dfbfe2a2a9db0a47 (diff)
downloadcouchdb-respect-FDB_CLUSTER_FILE.tar.gz
Add some unit testsrespect-FDB_CLUSTER_FILE
-rw-r--r--src/fabric/src/fabric2_server.erl69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/fabric/src/fabric2_server.erl b/src/fabric/src/fabric2_server.erl
index f5565c95f..e427f2013 100644
--- a/src/fabric/src/fabric2_server.erl
+++ b/src/fabric/src/fabric2_server.erl
@@ -349,3 +349,72 @@ sanitize(#{} = Db) ->
security_fun := undefined,
interactive := false
}.
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+setup() ->
+ meck:new(file, [unstick, passthrough]),
+ meck:expect(file, read_file_info, fun
+ ("ok.cluster", _) ->
+ {ok, #file_info{access = read_write}};
+ ("readonly.cluster", _) ->
+ {ok, #file_info{access = read}};
+ ("noaccess.cluster", _) ->
+ {ok, #file_info{access = none}};
+ ("missing.cluster", _) ->
+ {error, enoent};
+ (Path, Options) ->
+ meck:passthrough([Path, Options])
+ end).
+
+teardown(_) ->
+ meck:unload().
+
+find_cluster_file_test_() ->
+ {setup,
+ fun setup/0,
+ fun teardown/1,
+ [
+ {"ignore unspecified config", ?_assertEqual(
+ {ok, "ok.cluster"},
+ find_cluster_file([
+ {custom, undefined},
+ {custom, "ok.cluster"}
+ ])
+ )},
+
+ {"allow read-only file", ?_assertEqual(
+ {ok, "readonly.cluster"},
+ find_cluster_file([
+ {custom, "readonly.cluster"}
+ ])
+ )},
+
+ {"fail if no access to configured cluster file", ?_assertEqual(
+ {error, cluster_file_permissions},
+ find_cluster_file([
+ {custom, "noaccess.cluster"}
+ ])
+ )},
+
+ {"fail if configured cluster file is missing", ?_assertEqual(
+ {error, enoent},
+ find_cluster_file([
+ {custom, "missing.cluster"},
+ {default, "ok.cluster"}
+ ])
+ )},
+
+ {"check multiple default locations", ?_assertEqual(
+ {ok, "ok.cluster"},
+ find_cluster_file([
+ {default, "missing.cluster"},
+ {default, "ok.cluster"}
+ ])
+ )}
+ ]
+ }.
+
+-endif.