a7omiton
a7omiton

Reputation: 1617

How to test a CPAN package that requires having user credentials

I'm in the process of making a module that I plan to distribute on CPAN that is a client library for a public API.

The API requires API credentials (client_id/secret), and I'm not sure what the best practice is in regards to running Perl tests for a distribution with such credentials.

Do I:

Upvotes: 3

Views: 89

Answers (2)

Ivan Baidakou
Ivan Baidakou

Reputation: 783

I don't think, that this is a good idea to BAIL_OUT for common tests, run automatically by cpan-testers and on module installation.

I think you should just move your test into xt directory (authors test), which will be run only by you. And yes, best way to transfer credentials is via ENV, as mob suggested.

Upvotes: 0

mob
mob

Reputation: 118615

Have the tests expect the credentials in environment variables (or if they are long or complicated, a config file). When the credentials are not provided, have the test issue a warning with instructions about performing the tests with credentials.

 use Test::More;

 unless ($ENV{MY_ID} && $ENV{MY_PWD}) {
     BAIL_OUT "*** This module requires credentials. Pass them in the
           MY_ID and MY_PWD environment variables, like 

                 MY_ID=username MY_PWD=passwd make test";
 }

Automated test systems (such as what many CPANTesters use) will never configure a module before it is tested, so the BAIL_OUT registers the test result on CPAN Testers as an "N/A" as opposed to a fail.

Upvotes: 5

Related Questions