diff --git a/tests/users.py b/tests/users.py new file mode 100644 index 00000000..755b1529 --- /dev/null +++ b/tests/users.py @@ -0,0 +1,32 @@ +""" +Test that User name and ID mapping works +""" +import os +import subprocess +import tempfile +import time + +def test_user(): + """ + Validate user id and name setting + """ + ts = str(time.time()) + with tempfile.TemporaryDirectory() as tmpdir: + username = os.getlogin() + subprocess.check_call([ + 'repo2docker', + '-v', '{}:/home/{}'.format(tmpdir, username), + '--user-id', '1000', + '--user-name', 'yuvipanda', + tmpdir, + '--', + '/bin/bash', + '-c', 'id -u > id && pwd > pwd && whoami > name'.format(ts) + ]) + + with open(os.path.join(tmpdir, 'id')) as f: + assert f.read().strip() == '1000' + with open(os.path.join(tmpdir, 'pwd')) as f: + assert f.read().strip() == '/home/yuvipanda' + with open(os.path.join(tmpdir, 'name')) as f: + assert f.read().strip() == 'yuvipanda'