Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests to not require the stanley system_user? #6203

Open
cognifloyd opened this issue May 24, 2024 · 1 comment
Open

Fix unit tests to not require the stanley system_user? #6203

cognifloyd opened this issue May 24, 2024 · 1 comment

Comments

@cognifloyd
Copy link
Member

I'm working on getting pants to run our unit tests via pytest (I figure we can deal with integration tests later once all unit tests are running). I've got most of the st2common unit tests passing, but I've run into an assumption in our test suite that I would like to get rid of. The question is how.

Problematic assumption: That the system running our tests has the system_user (typically stanley).

For GHA, we had to add setup tasks that modify the conf files to use runner instead of stanley... But then we also create the stanley user "for ssh".
For vagrant, adding a user is not a big ask. Similar for docker containers.
But for local development (eg with vim, or with PyCharm, or whatever people prefer), I want to be able to at least run the unit tests without creating that user.

What's worse, the tests fail without indicating that the reason they failed was because the stanley user is not present.
I noticed in the log output that the core.echo action was triggering the command: sudo -E -H -u stanley -- bash -c 'echo "<% ctx().msg1 %>"' which was weird because the sudo parameter was false in the test's sample workflow. Apparently, the local-command-runner will use sudo -u <system_user> if the current user is not the same as system_user.

How can we make the default system_user match the current user, at least for unit tests?
Maybe whatever solution we come up with will lead to removing those GHA user setup tasks for the unit tests (requiring the user for integration tests doesn't bother me).

@cognifloyd
Copy link
Member Author

Here's one solution: 769e741

It doesn't set system_user.user to the current user by default, so people will still get weird errors until they figure out they need this and then they set the ST2TESTS_SYSTEM_USER env var with something like export ST2TESTS_SYSTEM_USER=${USER}. But, it's an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant