This uses testthat
for testing; maintainers and contributors should read these notes carefully.
This package is largely an API package, and testing a real API is tricky.
The implementation here takes some ideas from framework for APIs/secrets described
here and
here.
Basically, the above suggests:
-
We encrypt the appropriate
SYNAPSE_AUTH_TOKEN
secret withPKG_PWD
as key. Commit the encrypted secret as e.g.ins/secret.rds
. See https://github.com/r-lib/gargle/tree/main/inst/secret. -
Then depending on the test environment:
a) For testing locally, store in .Renviron the variablePKG_PWD
used to decryptSYNAPSE_AUTH_TOKEN
.
b) For testing with Github CI, storePKG_PWD
as secret in the test environment. -
Only if
PKG_PWD
is accessible to get decryptedSYNAPSE_AUTH_TOKEN
are tests run.
However, there are some limitations to this approach; see especially the first reference. To make this easier, the main adaptations are:
-
We DO NOT use a committed encrypted
SYNAPSE_AUTH_TOKEN
. It is expected that contributors are members of the NF-OSI team and create their own testSYNAPSE_AUTH_TOKEN
and set that asTEST_SYNAPSE_AUTH_TOKEN
in their .Renviron file; this token will automatically have access to the test repo. (Tests that write data run on assets in the test repo only.) If you are a potential contributor who is not an NF-OSI member, request to be added to the test repo for writing/running tests. IfTEST_SYNAPSE_AUTH_TOKEN
is not available, dependent tests are simply skipped. -
During tests, the
TEST_SYNAPSE_AUTH_TOKEN
is temporarily set asSYNAPSE_AUTH_TOKEN
. -
For pkg testing during development:
- Use
testthat::test_local()
in the pkg root to test all functions. Recommended. - Write a
test_that
function to test a new package function and run it interactively. Notetest_local
does things like importing Python modules into the environment (i.e. all the stuff that happens during package load), so the standalone function testing is a little trickier in having check for and set up dependencies in the environment.
- Use
-
Given that most tests depend on a successful login, and that tests are run according to the alphabetical naming of test*.R files,
test_auth_login.R
is named as such to ensure that it runs first (the order configuration can be encoded formally in DESCRIPTION later if needed). Because the testthat environment inherits from the global environment, the synapseclient will be available aftertest_auth_login.R
.
Known issues:
- Make sure the global environment is truly cleared before running
devtools::test()
. If.syn
pointer is still around from a previous call, this causes some issues.