-
Notifications
You must be signed in to change notification settings - Fork 72
fix: Load routes via store #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: edge
Are you sure you want to change the base?
Conversation
| [ | ||
| #{ <<"store-module">> => hb_store_gateway, | ||
| <<"routes">> => [], | ||
| <<"only">> => local |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| ?assertMatch( | ||
| not_found, | ||
| hb_cache:read( | ||
| <<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>, | ||
| Opts | ||
| ) | ||
| ). |
There was a problem hiding this comment.
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.
src/dev_router.erl
Outdated
| 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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| [ | ||
| #{ <<"store-module">> => hb_store_fs, <<"name">> => <<"cache-mainnet">> }, | ||
| #{ <<"store-module">> => hb_store_gateway, <<"store">> => false } | ||
| #{ <<"store-module">> => hb_store_gateway, <<"store">> => [] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since now <<"routes">> is converted to routes atom, false is not an acceptable result.
|
Nice! Thank you.
Let's avoid using the mock HTTP server unless absolutely necessary. Particularly if we are dependent on external services (GQL) for the test anyway. Mind removing that please? Then I will merge. Thanks! |
In this case, I'm not sure what other options I can use. I want to avoid:
I think the only solution is to return a response with the custom data we want. |
|
I've found an alternative to mock server by using the device |
This fix enables the use of custom store routes by modifying
<<"routes">>toroutes, allowing it to be picked up by the configuration. https://github.com/permaweb/HyperBEAM/blob/edge/src/dev_router.erl#L289There was already a test to check this functionality, but it was incomplete due to missing parameters in the configuration, causing a
not_foundto be returned, but not for the reason we wanted (to test theroutes). I've changed this to use the mock server to provide the object data and the other information is provided by GraphQL (maybe I can mock this as well to not rely on external endpoints).