summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-27 15:41:58 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-27 15:43:05 +0200
commit02d632e75a20c5c2540d4dc703289581f60047f4 (patch)
tree884408687ac6520d3986e351a6c1b34694a93495
parenta858b23414005c13f208cbfcaa070784f923ea61 (diff)
downloadgemato-02d632e75a20c5c2540d4dc703289581f60047f4.tar.gz
Add tests for CLI routines
-rw-r--r--tests/test_openpgp.py43
-rw-r--r--tests/test_recursiveloader.py112
2 files changed, 155 insertions, 0 deletions
diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py
index 17a43ae..c3f61d2 100644
--- a/tests/test_openpgp.py
+++ b/tests/test_openpgp.py
@@ -9,6 +9,7 @@ import shutil
import tempfile
import unittest
+import gemato.cli
import gemato.compression
import gemato.manifest
import gemato.openpgp
@@ -210,6 +211,27 @@ class SignedManifestTest(unittest.TestCase):
finally:
shutil.rmtree(d)
+ def test_cli(self):
+ d = tempfile.mkdtemp()
+ try:
+ with io.open(os.path.join(d, 'Manifest'), 'w') as f:
+ f.write(MODIFIED_SIGNED_MANIFEST)
+
+ os.mkdir(os.path.join(d, 'eclass'))
+ with io.open(os.path.join(d, 'eclass/Manifest'), 'w'):
+ pass
+ with io.open(os.path.join(d, 'myebuild-0.ebuild'), 'wb') as f:
+ f.write(b'12345678901234567890123456789012')
+ with io.open(os.path.join(d, 'metadata.xml'), 'w'):
+ pass
+
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify',
+ '--no-openpgp-verify', d]),
+ 0)
+ finally:
+ shutil.rmtree(d)
+
class OpenPGPCorrectKeyTest(unittest.TestCase):
"""
@@ -293,6 +315,27 @@ class OpenPGPCorrectKeyTest(unittest.TestCase):
finally:
shutil.rmtree(d)
+ def test_cli(self):
+ d = tempfile.mkdtemp()
+ try:
+ with io.open(os.path.join(d, 'Manifest'), 'w') as f:
+ f.write(SIGNED_MANIFEST)
+
+ os.mkdir(os.path.join(d, 'eclass'))
+ with io.open(os.path.join(d, 'eclass/Manifest'), 'w'):
+ pass
+ with io.open(os.path.join(d, 'myebuild-0.ebuild'), 'w'):
+ pass
+ with io.open(os.path.join(d, 'metadata.xml'), 'w'):
+ pass
+
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify',
+ '--require-signed-manifest', d]),
+ 0)
+ finally:
+ shutil.rmtree(d)
+
class OpenPGPNoKeyTest(unittest.TestCase):
"""
diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py
index 25aa382..8eac573 100644
--- a/tests/test_recursiveloader.py
+++ b/tests/test_recursiveloader.py
@@ -9,6 +9,7 @@ import gzip
import io
import os
+import gemato.cli
import gemato.exceptions
import gemato.recursiveloader
@@ -232,6 +233,37 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e
self.assertFalse(m.assert_directory_verifies(
'sub', fail_handler=lambda x: False))
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify',
+ os.path.join(self.dir, 'other')]),
+ 0)
+
+ def test_cli_verifies_stray_file(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify',
+ os.path.join(self.dir, 'sub')]),
+ 1)
+
+ def test_cli_verifies_stray_file_keep_going(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', '--keep-going',
+ os.path.join(self.dir, 'sub')]),
+ 1)
+
+ def test_cli_verifies_stray_file_nonstrict(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', '--no-strict',
+ os.path.join(self.dir, 'sub')]),
+ 1)
+
+ def test_cli_fails_without_signed_manifest(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify',
+ '--require-signed-manifest',
+ os.path.join(self.dir, 'other')]),
+ 1)
+
class MultipleManifestTest(TempDirTestCase):
DIRS = ['sub']
@@ -509,6 +541,11 @@ DATA test 0 SHA1 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
('SHA1', '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12', 'da39a3ee5e6b4b0d3255bfef95601890afd80709'),
])
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
class DuplicateIncompatibleDataMiscTypeFileEntryTest(TempDirTestCase):
"""
@@ -640,6 +677,11 @@ DATA test.ebuild 0 MD5 9e107d9d372bb6826bd81d3542a419d6
self.assertRaises(gemato.exceptions.ManifestIncompatibleEntry,
m.assert_directory_verifies, '')
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
class ManifestIgnoreEntryTest(TempDirTestCase):
"""
@@ -668,6 +710,11 @@ IGNORE bar
os.path.join(self.dir, 'Manifest'))
m.assert_directory_verifies('')
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 0)
+
class ManifestMiscEntryTest(TempDirTestCase):
"""
@@ -704,6 +751,16 @@ MISC foo 0 MD5 d41d8cd98f00b204e9800998ecf8427e
self.assertTrue(m.assert_directory_verifies('',
fail_handler=lambda x: True))
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
+ def test_cli_verifies_nonstrict(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]),
+ 0)
+
class ManifestOptionalEntryTest(TempDirTestCase):
"""
@@ -735,6 +792,16 @@ OPTIONAL foo
self.assertFalse(m.assert_directory_verifies('',
warn_handler=lambda x: False))
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
+ def test_cli_verifies_nonstrict(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]),
+ 0)
+
class CrossDeviceManifestTest(TempDirTestCase):
"""
@@ -769,6 +836,16 @@ DATA sub/version 0 MD5 d41d8cd98f00b204e9800998ecf8427e
fail_handler=lambda x: True,
warn_handler=lambda x: True)
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
+ def test_cli_verifies_nonstrict(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]),
+ 1)
+
class CrossDeviceEmptyManifestTest(TempDirTestCase):
"""
@@ -802,6 +879,16 @@ class CrossDeviceEmptyManifestTest(TempDirTestCase):
fail_handler=lambda x: True,
warn_handler=lambda x: True)
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
+ def test_cli_verifies_nonstrict(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]),
+ 1)
+
class CrossDeviceIgnoreManifestTest(TempDirTestCase):
"""
@@ -828,6 +915,11 @@ IGNORE sub
os.path.join(self.dir, 'Manifest'))
m.assert_directory_verifies('')
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 0)
+
class DotfileManifestTest(TempDirTestCase):
"""
@@ -846,6 +938,11 @@ class DotfileManifestTest(TempDirTestCase):
os.path.join(self.dir, 'Manifest'))
m.assert_directory_verifies()
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 0)
+
class DirectoryInPlaceOfFileManifestTest(TempDirTestCase):
"""
@@ -865,6 +962,11 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e
self.assertRaises(gemato.exceptions.ManifestMismatch,
m.assert_directory_verifies)
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 1)
+
class UnreadableDirectoryTest(TempDirTestCase):
"""
@@ -918,6 +1020,11 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e
self.manifest_gz)
m.assert_directory_verifies('')
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 0)
+
class CompressedSubManifestTest(TempDirTestCase):
"""
@@ -956,3 +1063,8 @@ MANIFEST sub/Manifest.gz 78 MD5 9c158f87b2445279d7c8aac439612fba
m = gemato.recursiveloader.ManifestRecursiveLoader(
os.path.join(self.dir, 'Manifest'))
m.assert_directory_verifies('')
+
+ def test_cli_verifies(self):
+ self.assertEqual(
+ gemato.cli.main(['gemato', 'verify', self.dir]),
+ 0)