summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-05-26 16:32:16 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-05-26 16:38:25 +0100
commit89ebc5fb7cd89ffc5598d31284db026e09408982 (patch)
tree2d064e4a05fc07869a2814931f3e5f9e6c604156
parentbdd6ad51cb13018a037ff06b54c3e4ee98e71785 (diff)
downloadsandboxlib-89ebc5fb7cd89ffc5598d31284db026e09408982.tar.gz
Add a basic test suite using 'py.test' and 'tox'
-rw-r--r--HACKING.mdwn15
-rw-r--r--tests/test_all.py54
-rw-r--r--tox.ini6
3 files changed, 74 insertions, 1 deletions
diff --git a/HACKING.mdwn b/HACKING.mdwn
index c294217..c118e30 100644
--- a/HACKING.mdwn
+++ b/HACKING.mdwn
@@ -1,3 +1,16 @@
+The 'sandboxlib' library uses the PEP-8 coding style, as a guide.
+
+# Running the automated test suite
+
+Use `tox`. You'll need 'py.test', 'tox' and their dependencies available.
+
+Note that a lot of the tests will be skipped if you don't run as 'root',
+because some of the sandboxing backends only work when you are the 'root' user.
+
+You can also run `PYTHONPATH=. py.test`, which is quicker but only tests with
+a single version of Python, and runs in your host environment rather than a
+clean one managed by 'virtualenv'.
+
# Testing that a sandbox conforms to the App Container spec
The [App Container project] provides an 'ace' package containing a
@@ -18,7 +31,7 @@ Container images.
Then, use the `run-sandbox` program from this repository to run the image:
- run-sandbox appc-spec/ace/build/ace-validator-main.aci
+ run-sandbox appc-spec/ace/build/ace-validator-main.aci -e linux-user-chroot
[App Container project]: https://github.com/appc/spec
diff --git a/tests/test_all.py b/tests/test_all.py
new file mode 100644
index 0000000..40688f2
--- /dev/null
+++ b/tests/test_all.py
@@ -0,0 +1,54 @@
+# Copyright (C) 2015 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+'''Functional ('black-box') tests for all 'sandboxlib' backends.
+
+FIXME: right now this is incomplete! Needs to introspect more!
+
+'''
+
+
+import pytest
+
+import os
+
+import sandboxlib
+
+
+@pytest.fixture(params=['chroot', 'linux_user_chroot'])
+def sandboxlib_executor(request):
+ executor = getattr(sandboxlib, request.param)
+
+ if request.param == 'chroot' and os.getuid() != 0:
+ pytest.skip('chroot backend can only be used by root users')
+
+ return executor
+
+
+def test_stdout(sandboxlib_executor):
+ exit, out, err = sandboxlib_executor.run_sandbox('/', ['echo', 'xyzzy'])
+
+ assert exit == 0
+ assert out.decode('unicode-escape') == 'xyzzy\n'
+ assert err.decode('unicode-escape') == ''
+
+
+def test_current_working_directory(sandboxlib_executor, tmpdir):
+ exit, out, err = sandboxlib_executor.run_sandbox(
+ '/', ['pwd'], cwd=str(tmpdir))
+
+ assert exit == 0
+ assert out.decode('unicode-escape') == '%s\n' % str(tmpdir)
+ assert err.decode('unicode-escape') == ''
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..7f5e569
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,6 @@
+[tox]
+envlist = py27,py33,py34
+
+[testenv]
+deps=pytest
+commands=py.test