Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Run bats test as "login user" #16

Closed
diclophis opened this issue Jul 8, 2013 · 1 comment
Closed

Run bats test as "login user" #16

diclophis opened this issue Jul 8, 2013 · 1 comment

Comments

@diclophis
Copy link

I am currently using bats (via way of busser-bats via test-kitchen + kitchen-vagrant) ... I am not sure this is even the correct layer to ask this question but here goes...

I wish to run the bats test suite as the "vagrant" user (or in a general sense, the original user used to shell into my test-kitchen host)

At the moment it appears that my bats test suites run as the "root" user (likely via some sudoing done in the test-kitchen/busser/bats integration) and I have to work around this inorder to test certain things (like rvm installations for my user)

Below is an example of how I get around the issue to test that I have the right version of ruby

    @test "has default ruby version 2.0.0p195" {
       sudo -E -u $SUDO_USER bash -l -c 'ruby -v | grep 2.0.0p195'
     }

This works ok, but it sorta clutters up the test suite code (I am currently working on making it a re-usable function) but I was wondering if there was anything I could just configure to make it use the "logged in user" by default?

Side note, the user switching also causes issues with SSH agent forwarding ENVs and to make things as simple as possible I would like to execute my test suite as the logged in user, and then sudo -uroot where necessary (to prevent double user switching hops and having to carry the ENV through each one)

@sstephenson
Copy link
Owner

I think you'll want to switch users before you invoke bats.

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

No branches or pull requests

2 participants