Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dev_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ apply_routes(Msg, R, Opts) ->
apply_route(Msg, Route, Opts) ->
% LoadedRoute = hb_cache:ensure_all_loaded(Route, Opts),
RouteOpts = hb_maps:get(<<"opts">>, Route, #{}),
RouteOpts2 = hb_opts:mimic_default_types(RouteOpts, existing, Opts),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly change http_client and protocol when loaded from config.flat with binary type to atom type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's collapse this rather than the *2

{ok, #{
<<"opts">> => RouteOpts,
<<"opts">> => RouteOpts2,
<<"uri">> =>
hb_util:ok(
do_apply_route(
Expand Down
46 changes: 36 additions & 10 deletions src/hb_store_gateway.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ read(BaseStoreOpts, Key) ->
%% @doc Normalize the routes in the given `Opts`.
opts(Opts) ->
case hb_maps:find(<<"node">>, Opts) of
error -> Opts;
error ->
hb_opts:mimic_default_types(Opts, existing, Opts);
{ok, Node} ->
case hb_maps:get(<<"node-type">>, Opts, <<"arweave">>, Opts) of
<<"arweave">> ->
Expand Down Expand Up @@ -215,22 +216,47 @@ cache_read_message_test() ->
%% know that the module is not respecting the route list.
specific_route_test() ->
hb_http_server:start_node(#{}),
%% Define the response we want
ID = <<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>,
Data = <<"specific_route_testx">>,
DefaultResponse = {200, Data},
Endpoints = [{<<"/raw/", ID/binary>>, ok, DefaultResponse}],
{ok, MockServer, _ServerHandle} = hb_mock_server:start(Endpoints),
%% Define configuration, we use a valid gateway to obtain a valid response
%% and then mock the raw endpoint to our mockserver.
Opts = #{
store =>
[
#{ <<"store-module">> => hb_store_gateway,
<<"routes">> => [],
<<"only">> => local
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed <<only>> => local because this will make us load everything necessary from the global configuration, like preloaded_devices, HTTP timeout configurations, and others. To test only routes, we don't need this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... Why would only => local do that? Its intention is to avoid looking up Opts from the global defaults table.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is the behavior that is shown here. By not loading the remaining configuration from the global defaults, the following modules, which need access to some of the defaults (like preloaded_devices), cannot function properly.

Because we're testing only a different routes configuration, we don't need to add only => local. If we add it, it will complain of no preloaded_devices being available.

<<"routes">> => [
#{
<<"template">> => <<"/graphql">>,
<<"nodes">> => [
#{
<<"prefix">> => <<"https://arweave-search.goldsky.com">>,
<<"opts">> => #{
<<"http_client">> => httpc,
<<"protocol">> => http2
}
}
]
},
#{
<<"template">> => <<"/raw">>,
<<"node">> =>
#{
<<"prefix">> => MockServer,
<<"opts">> => #{
<<"http_client">> => gun,
<<"protocol">> => http2
}
}
}
]
}
]
},
?assertMatch(
not_found,
hb_cache:read(
<<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>,
Opts
)
).
Comment on lines -227 to -233
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of error behaviours that mimic a "true" not_found output. Changed this to a value we expect.

?assertMatch({ok, #{<<"data">> := Data}}, hb_cache:read(ID, Opts)).

%% @doc Test that the default node config allows for data to be accessed.
external_http_access_test() ->
Expand Down