PopeFelix / Mojo-UserAgent-Mockable

A Mojo User Agent with similar functionality to LWP::UserAgent::Mockable
0 stars 12 forks source link

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

Open dmanto opened 3 years ago

dmanto commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

A chance? There's always a chance. lol. But I'm busy enough with @DayJob, and it's getting nice enough outside, that I don't have a lot of desire to do that. Still, you guys have helped me out a lot over the years and I feel like I oughtta. And it can't be that hard; I've written Role::Tiny roles before. Let me think about it some. And if some bright soul wants to take a stab at it before I get to it, I'm happy to consult.

On Mon, Mar 22, 2021 at 4:24 PM shadowcat-mst @.***> wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PopeFelix/Mojo-UserAgent-Mockable/issues/30#issuecomment-804405418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGUGGQWFM24PRLKLMZK7LTE6YRHANCNFSM4ZT44ZDA .

-- Kit Peters, W0KEH GPG public key fingerpint: D4FF AA62 AFEA 83D6 CC98 ACE5 6FAE 7E74 7F56 ED1D Hello to any and all NSA, DEA, or other government or non-government agents reading this email. Tell me about your life; I'll tell you about mine.

shadowcat-mst commented 3 years ago

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 commented 3 years ago

Here is a stab at it https://github.com/PopeFelix/Mojo-UserAgent-Mockable/compare/master...kiwiroy:recorder-role

PopeFelix commented 3 years ago

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