issue #339: minimal tests for lxc/lxd modules.

pull/350/head
David Wilson 6 years ago
parent 2c2fc73b0a
commit 6f524d3ff8

@ -52,7 +52,7 @@ class Stream(mitogen.parent.Stream):
super(Stream, self).construct(**kwargs)
self.container = container
if lxc_attach_path:
self.lxc_attach_path = lxc_attach_apth
self.lxc_attach_path = lxc_attach_path
def connect(self):
super(Stream, self).connect()

@ -0,0 +1,7 @@
#!/usr/bin/env python
import sys
import os
os.environ['ORIGINAL_ARGV'] = repr(sys.argv)
os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:])

@ -0,0 +1,7 @@
#!/usr/bin/env python
import sys
import os
os.environ['ORIGINAL_ARGV'] = repr(sys.argv)
os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:])

@ -0,0 +1,29 @@
import os
import mitogen
import unittest2
import testlib
def has_subseq(seq, subseq):
return any(seq[x:x+len(subseq)] == subseq for x in range(0, len(seq)))
class FakeLxcAttachTest(testlib.RouterMixin, unittest2.TestCase):
def test_okay(self):
lxc_attach_path = testlib.data_path('fake_lxc_attach.py')
context = self.router.lxc(
container='container_name',
lxc_attach_path=lxc_attach_path,
)
argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV'))
self.assertEquals(argv[0], lxc_attach_path)
self.assertTrue('--clear-env' in argv)
self.assertTrue(has_subseq(argv, ['--name', 'container_name']))
if __name__ == '__main__':
unittest2.main()

@ -0,0 +1,26 @@
import os
import mitogen
import unittest2
import testlib
class FakeLxcTest(testlib.RouterMixin, unittest2.TestCase):
def test_okay(self):
lxc_path = testlib.data_path('fake_lxc.py')
context = self.router.lxd(
container='container_name',
lxc_path=lxc_path,
)
argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV'))
self.assertEquals(argv[0], lxc_path)
self.assertEquals(argv[1], 'exec')
self.assertEquals(argv[2], '--force-noninteractive')
self.assertEquals(argv[3], 'container_name')
if __name__ == '__main__':
unittest2.main()
Loading…
Cancel
Save