create a keyring non-interactively (for unit tests)

I'm developing a package that builds on the keyring package. I'm trying to write my unit tests with testthat. I plan to write automated tests for everything non-interactive in my code, and for good measure right out manual tests for everything else.

There's just one problem: Literally everything I've written requires the user to create at least one keyring. But there is no parameterised keyring:: keyring_create() to allow me to automate the creation of a keyring sans interactivity.

I mean I suppose I could test my error messages no matter what. :rofl: But is there a way to create a dummy keyring (specifying a master password) in test environments (Windows, Linux, and Mac, all without user interaction) in order to test the rest of my code?

1 Like

This is a fairly uninformed answer, so I apologize if you’ve already been over this ground! Have you looked at how keyring’s own tests work? They seem to be doing non-interactive keyring creation:

2 Likes

Oh perfect! How did I miss that. I had actually looked at that file but... hadn't scrolled down far enough. :woman_facepalming:

It looks like that only tests on MacOS, though, and Mac is the only OS I don't have. Looks like now I just have to learn to configure Travis to make sure it runs MacOS!

Thank you! I think I can take this code as proof that it can't be done on Windows / Linux, so I'm marking your response as the solution. :grinning:

Oh no, I didn’t mean to give that impression! The keyring tests seem to be split up by backend (which kindasorta maps to OS), so you’ll probably want to inspect all the different test files for the backends that support multiple keyrings. For Windows, at least, there seems to be something similar going on, albeit less helpfully commented:

1 Like

Ohhhhhhhh wow above and beyond. Thank you so much! Couple of face palms in a row there. I swear I'm not usually so absent-minded.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.