Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^5: [RFC] Module code and POD for CPAN - Testing and test file

by choroba (Cardinal)
on Apr 16, 2021 at 06:55 UTC ( [id://11131361]=note: print w/replies, xml ) Need Help??


in reply to Re^4: [RFC] Module code and POD for CPAN - Testing and test file
in thread [RFC] Module code and POD for CPAN

> Is there a better way to handle the lack of API key?

Coincidentally, I blogged about mocking when I was improving the tests of Net::Stripe.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^6: [RFC] Module code and POD for CPAN - Testing and test file
by Bod (Parson) on Apr 16, 2021 at 19:40 UTC

    What a nice solution...thanks for sharing.

    For my module I don't have to handle state changes at the Stripe end. Not unless I implement shipping plans which is possible but not a high priority. Therefore, I've set up a script on my server that can provide a valid session object or a Stripe style error response. That way I can test for both scenarios. I've only implemented the success test so far but the fail will follow. There is a new (undocumented) url parameter that the tests use to access the test server.

    Being done over HTTP to a live server means that testing can happen without having to install Test::LWP::UserAgent on the target machine. I just hope that 20 billion people don't decide to install the module simultaneously!!!

    The tests are now split accross four files:

    00-load.tt 01-trolley.tt 02-stripe.t 03-stripe-live.t
    02 tests against the Stripe server and, of course, fails. 03 tests against my server so it should be able to get a live connection.

    Update:

    Turns out it is not that simple! As always...

    A check was added that an HTTP request gets a 200 status code and skips the live server tests if not. The network could be down at install time or it could be installed on a machine with no network connection - little point but folk do strange things!

    I was finding that more often than not the tests were being skipped. Turns out something in the request is tripping the server monitoring systems and blocking my IP address for anything from a couple of minutes to half an hour. So the live tests have been disabled in the test file until I can find what is causing this problem.

    The obvious things have been tried. Removing the Authorization header from the test request and ensuring the POST command doesn't have an empty payload. Time to scratch my head and search for inspiration...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found