Skip to content

Commit d971538

Browse files
BenHuddlestonPeter-Searby
authored andcommitted
MB-67857[BP]: Expand mecks in fake_ns_config
Add mecks for search_node and search_node_prop which will be used by future DCP tests. Add handlers to fetch these from the snapshot. Change-Id: Id7bcd72ef66c7551b2ab9699c9a77868e9612e33 Reviewed-on: https://review.couchbase.org/c/ns_server/+/232325 Well-Formed: Restriction Checker Tested-by: Peter Searby <[email protected]> Reviewed-by: Timofey Barmin <[email protected]>
1 parent 5a13ab5 commit d971538

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

test/fake_helpers/fake_ns_config.erl

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,35 @@ meck_setup_getters() ->
198198
end),
199199

200200

201+
meck:expect(ns_config, search_node,
202+
fun(Node, Snapshot, Key) ->
203+
fetch_node(Node, Snapshot, Key)
204+
end),
205+
206+
207+
meck:expect(ns_config, search_prop,
208+
fun(Snapshot, Key, SubKey, DefaultSubVal) ->
209+
fetch_prop(Snapshot, Key, SubKey, DefaultSubVal)
210+
end),
211+
212+
meck:expect(ns_config, search_node_prop,
213+
fun(?NS_CONFIG_LATEST_MARKER, Key, SubKey, Default) ->
214+
fetch_node_prop(node(), ?NS_CONFIG_LATEST_MARKER, Key,
215+
SubKey, Default);
216+
(Node, Snapshot, Key, SubKey) when is_atom(Node) ->
217+
fetch_node_prop(Node, Snapshot, Key, SubKey, undefined);
218+
(Snapshot, Key, SubKey, Default) ->
219+
fetch_node_prop(node(), Snapshot, Key, SubKey, Default)
220+
end),
221+
222+
223+
meck:expect(ns_config, search_node_prop,
224+
fun(Node, Snapshot, Key, SubKey, DefaultSubVal) ->
225+
fetch_node_prop(Node, Snapshot, Key, SubKey,
226+
DefaultSubVal)
227+
end),
228+
229+
201230
meck:expect(ns_config, search_node_with_default,
202231
fun(Key, Default) ->
203232
fetch_with_default_from_latest_snapshot(Key, Default)
@@ -243,7 +272,10 @@ store_ets_snapshot(Snapshot) ->
243272
ns_config:do_announce_changes(Diff).
244273

245274
fetch_from_snapshot(Snapshot, Key) ->
246-
{value, proplists:get_value(Key, Snapshot)}.
275+
case proplists:get_value(Key, Snapshot, not_found) of
276+
not_found -> false;
277+
V -> {value, V}
278+
end.
247279

248280
fetch_from_latest_snapshot(Key) ->
249281
fetch_from_snapshot(get_ets_snapshot(), Key).
@@ -256,3 +288,31 @@ fetch_with_default(Snapshot, Key, Default) ->
256288

257289
fetch_with_default_from_latest_snapshot(Key, Default) ->
258290
fetch_with_default(get_ets_snapshot(), Key, Default).
291+
292+
fetch_node_prop(Node, ?NS_CONFIG_LATEST_MARKER, Key, SubKey, Default) ->
293+
fetch_node_prop(Node, get_ets_snapshot(), Key, SubKey, Default);
294+
fetch_node_prop(Node, Snapshot, Key, SubKey, Default) ->
295+
case fetch_node(Node, Snapshot, Key) of
296+
{value, List} ->
297+
case proplists:lookup(SubKey, List) of
298+
none -> fetch_prop(Snapshot, Key, SubKey, Default);
299+
{SubKey, Val} -> Val
300+
end;
301+
false -> Default
302+
end.
303+
304+
fetch_node(Node, Snapshot, Key) ->
305+
case fetch_from_snapshot(Snapshot, {node, Node, Key}) of
306+
{value, _} = V -> V;
307+
false -> fetch_from_snapshot(Snapshot, Key)
308+
end.
309+
310+
fetch_prop(?NS_CONFIG_LATEST_MARKER, Key, SubKey, DefaultSubVal) ->
311+
fetch_prop(get_ets_snapshot(), Key, SubKey, DefaultSubVal);
312+
fetch_prop(Snapshot, Key, SubKey, DefaultSubVal) ->
313+
case fetch_from_snapshot(Snapshot, Key) of
314+
{value, PropList} ->
315+
proplists:get_value(SubKey, PropList, DefaultSubVal);
316+
false ->
317+
DefaultSubVal
318+
end.

0 commit comments

Comments
 (0)