2
0
mirror of https://github.com/cmehay/pyentrypoint synced 2024-10-30 15:21:11 +00:00
pyentrypoint/tests/main_test.py

100 lines
2.8 KiB
Python
Raw Normal View History

2016-05-08 15:11:01 +00:00
# Tests using pytest
import os
from multiprocessing import Process
2016-12-04 20:11:10 +00:00
from commons import clean_env
2016-05-08 15:11:01 +00:00
from pyentrypoint.entrypoint import main
2016-12-04 20:11:10 +00:00
def teardown_function(function):
clean_env()
2016-05-08 15:11:01 +00:00
class ProxyMain(object):
def __init__(self, args, env):
self.args = args
self.env = env
def run(self):
for key, val in self.env.items():
os.environ[key] = val
main(self.args)
def test_main():
run = [
# ((Process instance), (file to check), (uid), (gid))
(
Process(target=ProxyMain(
2016-09-22 23:14:54 +00:00
args=['pyentrypoint', '-c', 'echo OK > /tmp/CMD__6'],
2016-05-08 15:11:01 +00:00
env={'ENTRYPOINT_CONFIG': 'configs/base.yml'}
).run),
2016-09-22 23:14:54 +00:00
'/tmp/CMD__6',
2016-05-08 15:11:01 +00:00
1000,
1000,
), (
Process(target=ProxyMain(
args=['pyentrypoint',
'bash',
'-c',
2016-09-22 23:14:54 +00:00
'echo ${SECRET}OK > /tmp/CMD__7'],
2016-05-08 15:11:01 +00:00
env={'ENTRYPOINT_CONFIG': 'configs/base.yml'}
).run),
2016-09-22 23:14:54 +00:00
'/tmp/CMD__7',
2016-05-08 15:11:01 +00:00
1000,
1000,
), (
Process(target=ProxyMain(
2016-09-22 23:14:54 +00:00
args=['pyentrypoint', 'bash', '-c', 'echo OK > /tmp/CMD__8'],
2016-05-08 15:11:01 +00:00
env={'ENTRYPOINT_CONFIG': 'configs/usernames.yml'}
).run),
2016-09-22 23:14:54 +00:00
'/tmp/CMD__8',
1009,
1010,
2016-05-08 15:11:01 +00:00
), (
Process(target=ProxyMain(
2016-09-22 23:14:54 +00:00
args=['pyentrypoint', 'bash', '-c', 'echo OK > /tmp/CMD__9'],
2016-05-08 15:11:01 +00:00
env={'ENTRYPOINT_CONFIG': 'configs/unhandled.yml'}
).run),
2016-09-22 23:14:54 +00:00
'/tmp/CMD__9',
2016-05-08 15:11:01 +00:00
0,
0,
), (
Process(target=ProxyMain(
2016-09-22 23:14:54 +00:00
args=['pyentrypoint', 'bash', '-c', 'echo OK > /tmp/CMD__10'],
2016-05-08 15:11:01 +00:00
env={'ENTRYPOINT_CONFIG': 'configs/unhandled_force.yml',
'ENTRYPOINT_FORCE': 'true'}
).run),
'/tmp/CMD_FORCE',
0,
0,
), (
Process(target=ProxyMain(
2016-09-22 23:14:54 +00:00
args=['pyentrypoint', 'bash', '-c', 'echo OK > /tmp/CMD__11'],
2016-05-08 15:11:01 +00:00
env={'ENTRYPOINT_CONFIG': '/dontexist'}
).run),
2016-09-22 23:14:54 +00:00
'/tmp/CMD__11',
2016-05-08 15:11:01 +00:00
0,
0,
), (
Process(target=ProxyMain(
2016-09-22 23:14:54 +00:00
args=['pyentrypoint', 'bash', '-c', 'echo OK > /tmp/CMD__12'],
env={'ENTRYPOINT_CONFIG': 'configs/base_with_errors.yml'}
).run),
2016-09-22 23:14:54 +00:00
'/tmp/CMD__12',
1000,
1000,
2016-05-08 15:11:01 +00:00
)
]
for proc, test, uid, gid in run:
proc.start()
proc.join()
with open(test) as f:
assert f.readline().startswith('OK')
assert os.stat(test).st_uid == uid
assert os.stat(test).st_gid == gid