Created
July 11, 2017 09:33
-
-
Save stevendanna/2e132a0d59fd04b9de4fd2d7943f8f3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- | |
%%------------------------------------------------------------------- | |
%% @author Steven Danna <[email protected]> | |
%% Copyright 2017 Chef, Inc. All Rights Reserved. | |
%% | |
-module(node_state_tests). | |
-include_lib("eunit/include/eunit.hrl"). | |
-include_lib("hoax/include/hoax.hrl"). | |
-compile([export_all]). | |
set_expectations(LeaderKey, BootstrapKey) -> | |
hoax:expect(receive | |
leader_block_state:get() -> test_leader_block_state; | |
leader_key:get() -> LeaderKey; | |
bootstrap_key:get() -> BootstrapKey | |
end). | |
query_test_() -> | |
TestInfo = [ | |
{"when_all_keys_exist", | |
{ok, <<"test leader key">>}, {ok, <<"test bootstrap key">>}, | |
{ok, {test_leader_block_state, <<"test leader key">>, <<"test bootstrap key">>}}}, | |
{"when leader key does not exist", | |
{error, key_not_found},{ok, <<"test bootstrap key">>}, | |
{ok, {test_leader_block_state, no_leader, <<"test bootstrap key">>}}}, | |
{"when leader not ready", | |
{error, {leader_not_ready, <<"test leader key">>}}, {ok, <<"test bootstrap key">>}, | |
{ok, {test_leader_block_state, {leader_not_ready, <<"test leader key">>}, <<"test bootstrap key">>}}}, | |
{"when leader key errors", | |
{error, unknown_error}, {ok, <<"test bootstrap key">>}, | |
{error, unknown_error}}, | |
{"when_bootstrap_key_does_not_exist", | |
{ok, <<"test leader key">>}, {error, key_not_found}, | |
{ok, {test_leader_block_state, <<"test leader key">>, no_bootstrap_node}}}, | |
{"when bootstrap key errors", | |
{ok, <<"test leader key">>}, {error, unknown_error}, | |
{error, unknown_error}}], | |
{foreach, | |
fun() -> hoax:start() end, | |
fun(_) -> hoax:stop() end, | |
[{Name, fun() -> | |
set_expectations(LeaderKeyReturn, BootstrapKeyReturn), | |
?assertEqual(ExpectedResult, node_state:query()), | |
?verifyAll | |
end } || {Name, LeaderKeyReturn, BootstrapKeyReturn, ExpectedResult} <- TestInfo]}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment