Skip to content
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

Consider creating a sister module that defines a "Recorder" role for Mojo::Test #30

Open
dmanto opened this issue Mar 22, 2021 · 5 comments

Comments

@dmanto
Copy link

dmanto commented Mar 22, 2021

As for conversations at mojo IRC chat (Mar 22, 2021, starting at 10:35 AM GMT), Mojolicious developer (kraih) suggessted he was thinking on about writing a Mojo::UserAgent::Server module that runs the tests against the live service the first time and caches the responses in a t/fixtures/... dir

Further in the convesation mst mentioned this module (Mojo::UserAgent::Mockable), as a possible implementation.

Kraih's sugestion is that it should be a role, use could be like:

my $ua = Mojo::UserAgent->new->with_roles('+Recorder');
$ua->record_to('t/fixtures/cache');
my $maybe_cached_json = $ua->get('https://fastapi.metacpan.org/v1/module/_search?q=mojolicious')->result->json;

I asked at mojo chat if the proxy helpers (->proxy->get_p and post_p) could be also cached by the role. Use cases would to be able to test offline some proxied API (for instance a map API like mapbox, that is easily proxied in mojo through those helpers). kraih said he can contribute the proxy helpers as a contribution example.

Finally, and as an example of a mojo developer user's experience, one should be able to write a test that runs online with a caching flag, like

MOJO_UA_RECORDING_START=1 prove -l t/...

and then after that the test will be able to be run offline, (obviously w/o the env var set).

@shadowcat-mst
Copy link

Also your code basically already has the recorder stuff for the useragent, it just needs switchting to a Role::Tiny, and sri sez:

< kraih> then you could still use the role, nothing prevents you from making less efficient proxy helpers for testing that do use the recorder
< kraih> it's trivial if the recorder role exists, heck, if someone makes the role i'll contribute the proxy helpers as a documentation example :P

So, uh, any chance of refactoring your already working stuff into that role? :D

@PopeFelix
Copy link
Owner

PopeFelix commented Mar 22, 2021 via email

@shadowcat-mst
Copy link

Totally, dude, just if you can find time to do a bit of refactoring of what you already have, the author of Mojo is up for taking it from there ... and I'm interested enough to kick around and help out

@kiwiroy
Copy link

kiwiroy commented Mar 23, 2021

Here is a stab at it master...kiwiroy:recorder-role

@PopeFelix
Copy link
Owner

@kiwiroy That looks decent. Make it a PR? I'll want @shadowcat-mst to give it a once over as well.

@kiwiroy kiwiroy mentioned this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants