Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Flickr OAuth module and testing

by boftx (Deacon)
on May 21, 2015 at 08:30 UTC ( [id://1127310]=note: print w/replies, xml ) Need Help??


in reply to Flickr OAuth module and testing

Following up on what the esteemed Anonymous Monk wrote, I would suggest looking at Test::MockModule. I often run into the same situation and find that if I structure my code right I can mock calls to LWP, etc. and return known values so I can see how my code handles auth failures and various return codes.

Basically, you want to mock any method call that is outside your module that depends on a given resource already existing. Tedious, sometimes, but it can give you confidence that your code will handle what is thrown at you. I presume that you are really interested in your code dealing with various return values so being able to supply known good and bad results is what you want for testing.

I recall seeing a couple of modules designed specifically for mocking HTTP calls, try doing a CPAN search for Test::Mock and see what turns up.

You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Replies are listed 'Best First'.
Re^2: Flickr OAuth module and testing
by CountZero (Bishop) on May 21, 2015 at 13:56 UTC
    My module operates on a very basic level and does not really deal itself with failures and return codes. It just "manages" the OAuth protocol by
    1. crafting the messages based upon the IDs and secret codes provided, as well as tags, filenames, ... etc; and
    2. "carrying" these specially crafted messages to the Flickr OAUth-equipped server and obtaining a result code, JSON message or XML result (as the case may be)

    It is then up to the user to validate this reply.

    I think I can refactor my module into "crafting" subs and "transport" subs and test the "crafting" subs to see they conform to the OAuth standards en then test the "transport" layer only in case the user has provided his IDs and secret codes through some ENV-variables.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-18 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found