Skip to content

Commit

Permalink
fix: new singleton syntax in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samcamwilliams committed Jan 25, 2025
1 parent 1a0aad3 commit 2130746
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
26 changes: 13 additions & 13 deletions src/dev_meta.erl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ all_signers(Msgs) ->
%% @doc Test that we can get the node message.
config_test() ->
Node = hb_http_server:start_test_node(#{ test_config_item => <<"test">> }),
{ok, Res} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{ok, Res} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?event({res, Res}),
?assertEqual(<<"test">>, hb_converge:get(<<"test_config_item">>, Res, #{})).

Expand All @@ -166,7 +166,7 @@ priv_inaccessible_test() ->
priv_key => <<"BAD">>
}
),
{ok, Res} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{ok, Res} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?event({res, Res}),
?assertEqual(<<"test">>, hb_converge:get(<<"test_config_item">>, Res, #{})),
?assertEqual(not_found, hb_converge:get(<<"priv_key">>, Res, #{})).
Expand All @@ -180,15 +180,15 @@ unauthorized_set_node_msg_fails_test() ->
Node,
hb_message:sign(
#{
<<"path">> => <<"/![email protected]/info">>,
<<"path">> => <<"/~m[email protected]/info">>,
<<"evil_config_item">> => <<"BAD">>
},
ar_wallet:new()
),
#{}
),
?event({res, SetRes}),
{ok, Res} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{ok, Res} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?event({res, Res}),
?assertEqual(not_found, hb_converge:get(<<"evil_config_item">>, Res, #{})).

Expand All @@ -207,15 +207,15 @@ authorized_set_node_msg_succeeds_test() ->
Node,
hb_message:sign(
#{
<<"path">> => <<"/![email protected]/info">>,
<<"path">> => <<"/~m[email protected]/info">>,
<<"test_config_item">> => <<"test2">>
},
Owner
),
#{}
),
?event({res, SetRes}),
{ok, Res} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{ok, Res} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?event({res, Res}),
?assertEqual(<<"test2">>, hb_converge:get(<<"test_config_item">>, Res, #{})).

Expand All @@ -234,31 +234,31 @@ claim_node_test() ->
Node,
hb_message:sign(
#{
<<"path">> => <<"/![email protected]/info">>,
<<"path">> => <<"/~m[email protected]/info">>,
<<"operator">> => Address
},
Owner
),
#{}
),
?event({res, SetRes}),
{ok, Res} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{ok, Res} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?event({res, Res}),
?assertEqual(Address, hb_converge:get(<<"operator">>, Res, #{})),
{ok, SetRes2} =
hb_http:post(
Node,
hb_message:sign(
#{
<<"path">> => <<"/![email protected]/info">>,
<<"path">> => <<"/~m[email protected]/info">>,
<<"test_config_item">> => <<"test2">>
},
Owner
),
#{}
),
?event({res, SetRes2}),
{ok, Res2} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{ok, Res2} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?event({res, Res2}),
?assertEqual(<<"test2">>, hb_converge:get(<<"test_config_item">>, Res2, #{})).

Expand All @@ -278,7 +278,7 @@ preprocessor_test() ->
}
}
}),
hb_http:get(Node, <<"/![email protected]/info">>, #{}),
hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?assert(receive ok -> true after 1000 -> false end).

%% @doc Test that we can halt a request if the preprocessor returns an error.
Expand All @@ -295,7 +295,7 @@ halt_request_test() ->
}
}
}),
{error, Res} = hb_http:get(Node, <<"/![email protected]/info">>, #{}),
{error, Res} = hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?assertEqual(<<"Bad">>, Res).

%% @doc Test that a preprocessor can modify a request.
Expand Down Expand Up @@ -332,5 +332,5 @@ postprocessor_test() ->
}
}
}),
hb_http:get(Node, <<"/![email protected]/info">>, #{}),
hb_http:get(Node, <<"/~m[email protected]/info">>, #{}),
?assert(receive ok -> true after 1000 -> false end).
2 changes: 1 addition & 1 deletion src/dev_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ device_call_from_singleton_test() ->
<<"node">> => <<"old">>,
<<"priority">> => 10
}]},
Msgs = hb_singleton:from(#{ <<"path">> => <<"![email protected]/routes">> }),
Msgs = hb_singleton:from(#{ <<"path">> => <<"~r[email protected]/routes">> }),
?event({msgs, Msgs}),
?assertEqual(
{ok, Routes},
Expand Down
10 changes: 5 additions & 5 deletions src/dev_scheduler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ http_init(Opts) ->

http_post_schedule_sign(Node, Msg, ProcessMsg, Wallet) ->
Msg1 = hb_message:sign(#{
<<"path">> => <<"/![email protected]/schedule">>,
<<"path">> => <<"/~s[email protected]/schedule">>,
<<"method">> => <<"POST">>,
<<"process">> => ProcessMsg,
<<"body">> => hb_message:sign(Msg, Wallet)
Expand All @@ -504,14 +504,14 @@ http_post_schedule_sign(Node, Msg, ProcessMsg, Wallet) ->

http_get_slot(N, PMsg) ->
{ok, _} = hb_http:get(N, #{
<<"path">> => <<"/![email protected]/slot">>,
<<"path">> => <<"/~s[email protected]/slot">>,
<<"method">> => <<"GET">>,
<<"process">> => PMsg
}, #{}).

http_get_schedule(N, PMsg, From, To) ->
{ok, _} = hb_http:get(N, #{
<<"path">> => <<"/![email protected]/schedule">>,
<<"path">> => <<"/~s[email protected]/schedule">>,
<<"method">> => <<"GET">>,
<<"process">> => PMsg,
<<"from">> => From,
Expand All @@ -535,7 +535,7 @@ http_get_schedule_test() ->
{Node, Wallet} = http_init(),
PMsg = hb_message:sign(test_process(Wallet), Wallet),
Msg1 = hb_message:sign(#{
<<"path">> => <<"/![email protected]/schedule">>,
<<"path">> => <<"/~s[email protected]/schedule">>,
<<"method">> => <<"POST">>,
<<"process">> => PMsg,
<<"body">> => hb_message:sign(#{ <<"inner">> => <<"test">> }, Wallet)
Expand Down Expand Up @@ -598,7 +598,7 @@ many_clients(Opts) ->
{Node, Wallet} = http_init(Opts),
PMsg = hb_message:sign(test_process(Wallet), Wallet),
Msg1 = hb_message:sign(#{
<<"path">> => <<"/![email protected]/schedule">>,
<<"path">> => <<"/~s[email protected]/schedule">>,
<<"method">> => <<"POST">>,
<<"process">> => PMsg,
<<"body">> => hb_message:sign(#{ <<"inner">> => <<"test">> }, Wallet)
Expand Down
6 changes: 3 additions & 3 deletions src/dev_simple_pay.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ get_balance_and_top_up_test() ->
hb_http:get(
Node,
hb_message:sign(
#{<<"path">> => <<"/![email protected]/balance">>},
#{<<"path">> => <<"/~s[email protected]/balance">>},
Wallet
),
#{}
Expand All @@ -150,7 +150,7 @@ get_balance_and_top_up_test() ->
Node,
hb_message:sign(
#{
<<"path">> => <<"/![email protected]/topup">>,
<<"path">> => <<"/~s[email protected]/topup">>,
<<"amount">> => 100,
<<"recipient">> => Address
},
Expand All @@ -163,7 +163,7 @@ get_balance_and_top_up_test() ->
hb_http:get(
Node,
hb_message:sign(
#{<<"path">> => <<"/![email protected]/balance">>},
#{<<"path">> => <<"/~s[email protected]/balance">>},
Wallet
),
#{}
Expand Down
10 changes: 7 additions & 3 deletions src/hb_http_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ get_opts(NodeMsg) ->
%%% Tests

test_opts(Opts) ->
rand:seed(default),
% Generate a random port number between 42000 and 62000 to use
% for the server.
rand:seed(exsplus, erlang:timestamp()),
Port = 10000 + rand:uniform(20000),
Port =
case hb_opts:get(port, no_port, Opts) of
no_port ->
rand:seed(exsplus, erlang:timestamp()),
10000 + rand:uniform(20000);
PassedPort -> PassedPort
end,
Wallet =
case hb_opts:get(priv_wallet, no_viable_wallet, Opts) of
no_viable_wallet -> ar_wallet:new();
Expand Down

0 comments on commit 2130746

Please sign in to comment.