tests: add basic test for qvm-features

This commit is contained in:
Marek Marczykowski-Górecki 2017-01-14 04:56:19 +01:00
parent 0b7145f67d
commit c3fc4062d8
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 72 additions and 0 deletions

View File

@ -908,6 +908,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
# tool tests
'qubes.tests.integ.tools.qubes_create',
'qubes.tests.integ.tools.qvm_check',
'qubes.tests.integ.tools.qvm_features',
'qubes.tests.integ.tools.qvm_firewall',
'qubes.tests.integ.tools.qvm_prefs',
'qubes.tests.integ.tools.qvm_run',

View File

@ -0,0 +1,70 @@
#!/usr/bin/python2
# -*- encoding: utf8 -*-
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2017 Marek Marczykowski-Górecki
# <marmarek@invisiblethingslab.com>
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import qubes
import qubes.tools.qvm_features
import qubes.tests
import qubes.tests.tools
import qubes.vm.appvm
class TC_00_qvm_features(qubes.tests.SystemTestsMixin,
qubes.tests.QubesTestCase):
def setUp(self):
super(TC_00_qvm_features, self).setUp()
self.init_default_template()
self.sharedopts = ['--qubesxml', qubes.tests.XMLPATH]
self.vm1 = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('vm1'),
template=self.app.default_template,
label='red')
self.app.save()
def test_000_list(self):
self.assertEqual(0, qubes.tools.qvm_features.main(
self.sharedopts + [self.vm1.name]))
with self.assertRaises(SystemExit):
qubes.tools.qvm_features.main(
self.sharedopts + ['test-no-such-vm'])
def test_001_get_missing(self):
self.assertEqual(1, qubes.tools.qvm_features.main(
self.sharedopts + [self.vm1.name, 'no-such-feature']))
def test_002_set_and_get(self):
self.assertEqual(0, qubes.tools.qvm_features.main(
self.sharedopts + [self.vm1.name, 'test-feature', 'true']))
with qubes.tests.tools.StdoutBuffer() as buf:
self.assertEqual(0, qubes.tools.qvm_features.main(
self.sharedopts + [self.vm1.name, 'test-feature']))
self.assertEqual('true\n', buf.getvalue())
def test_003_set_and_list(self):
self.assertEqual(0, qubes.tools.qvm_features.main(
self.sharedopts + [self.vm1.name, 'test-feature', 'true']))
with qubes.tests.tools.StdoutBuffer() as buf:
self.assertEqual(0, qubes.tools.qvm_features.main(
self.sharedopts + [self.vm1.name]))
self.assertEqual('test-feature true\n', buf.getvalue())

View File

@ -358,6 +358,7 @@ fi
%{python3_sitelib}/qubes/tests/integ/tools/__pycache__/*
%{python3_sitelib}/qubes/tests/integ/tools/__init__.py
%{python3_sitelib}/qubes/tests/integ/tools/qubes_create.py
%{python3_sitelib}/qubes/tests/integ/tools/qvm_features.py*
%{python3_sitelib}/qubes/tests/integ/tools/qvm_firewall.py
%{python3_sitelib}/qubes/tests/integ/tools/qvm_check.py
%{python3_sitelib}/qubes/tests/integ/tools/qvm_prefs.py