From: Markus Lehtonen Date: Wed, 25 Feb 2015 20:03:13 +0000 (+0200) Subject: rpm tests: add unit tests for buildpackage-rpm X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc09447a102ac43565e76ef028b97f797cbd4f51;p=tools%2Fgit-buildpackage.git rpm tests: add unit tests for buildpackage-rpm Signed-off-by: Markus Lehtonen --- diff --git a/packaging/git-buildpackage.spec b/packaging/git-buildpackage.spec index 048bf29a..3bdfa05d 100644 --- a/packaging/git-buildpackage.spec +++ b/packaging/git-buildpackage.spec @@ -67,6 +67,7 @@ BuildRequires: python-nose BuildRequires: git-core BuildRequires: %{man_pkg_name} BuildRequires: %{dpkg_pkg_name} +BuildRequires: rpm-build BuildRequires: %{rpm_python_pkg_name} BuildRequires: pristine-tar BuildRequires: unzip diff --git a/tests/component/rpm/test_buildpackage_rpm.py b/tests/component/rpm/test_buildpackage_rpm.py index b9f33aec..e60f54af 100644 --- a/tests/component/rpm/test_buildpackage_rpm.py +++ b/tests/component/rpm/test_buildpackage_rpm.py @@ -29,7 +29,7 @@ from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611 from gbp.git import GitRepository from gbp.scripts.buildpackage_rpm import main as gbp_rpm from tests.component.rpm import RpmRepoTestBase, RPM_TEST_DATA_DIR -from tests.testutils import ls_tar, ls_zip +from tests.testutils import ls_dir, ls_tar, ls_zip # Disable "Method could be a function warning" # pylint: disable=R0201 @@ -128,7 +128,7 @@ class TestGbpRpm(RpmRepoTestBase): self.check_rpms('../rpmbuild/RPMS/*') shutil.rmtree('../rpmbuild') - eq_(mock_gbp(['--git-native=off']), 1) + eq_(mock_gbp(['--git-native=off']), 2) self._check_log(0, 'gbp:error: Invalid upstream treeish upstream/') def test_native_build2(self): @@ -298,14 +298,29 @@ class TestGbpRpm(RpmRepoTestBase): # Test invalid upstream treeish eq_(mock_gbp(['--git-upstream-tree=TAG', - '--git-upstream-tag=invalid-tag']), 1) + '--git-upstream-tag=invalid-tag']), 2) self._check_log(-1, ".*Invalid upstream treeish invalid-tag") eq_(mock_gbp(['--git-upstream-tree=BRANCH', '--git-native=no', - '--git-upstream-branch=invalid-branch']), 1) + '--git-upstream-branch=invalid-branch']), 2) self._check_log(-1, ".*invalid-branch is not a valid branch") - eq_(mock_gbp(['--git-upstream-tree=invalid-tree']), 1) + eq_(mock_gbp(['--git-upstream-tree=invalid-tree']), 2) self._check_log(-1, ".*Invalid treeish object") + def test_option_orig_prefix(self): + """Test the --git-orig-prefix option""" + repo = self.init_test_repo('gbp-test') + + # Building with invalid prefix should fail + eq_(mock_gbp(['--git-orig-prefix=foo']), 1) + upstr_branch = 'srcdata/gbp-test/upstream' + ref_files = ['foo/' + path for path in self.ls_tree(repo, upstr_branch)] + tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False) + self.check_files(tar_files, ref_files) + + # Test invalid keys + eq_(mock_gbp(['--git-orig-prefix=%(foo)s', '--git-no-build']), 1) + self._check_log(-1, ".*Missing value 'foo' in") + def test_pristine_tar(self): """Test pristine-tar""" repo = self.init_test_repo('gbp-test') @@ -413,7 +428,7 @@ class TestGbpRpm(RpmRepoTestBase): shutil.rmtree('gbp-test-native.repo') repo.create('gbp-test-native.repo') eq_(mock_gbp(['--git-submodules', '--git-upstream-tree=%s' % - upstr_branch, '--git-ignore-untracked']), 1) + upstr_branch, '--git-ignore-untracked']), 2) def test_option_submodules_native(self): """Test the --git-submodules option for native packages""" @@ -463,6 +478,7 @@ class TestGbpRpm(RpmRepoTestBase): args = fobj.read() eq_(args, '--arg1 --arg2 gbp-test-native.spec') + def test_option_cleaner(self): """Test --git-cleaner option""" self.init_test_repo('gbp-test-native') @@ -654,3 +670,65 @@ class TestGbpRpm(RpmRepoTestBase): eq_(mock_gbp(['--git-spec-vcs-tag=%(invalid-key)s']), 1) self._check_log(-1, r".*Failed to format %\(invalid-key\)s") + def test_patch_export_options(self): + """Test patch export options""" + repo = self.init_test_repo('gbp-test2') + + # Test no-patch-export + base_args = ['--git-no-build', '--git-export-specdir=', + '--git-export-sourcedir='] + eq_(mock_gbp(base_args + ['--git-no-patch-export']), 0) + ref_files = self.ls_tree(repo, 'HEAD:packaging') + ref_files.add('gbp-test2-2.0.tar.gz') + self.check_files(ref_files, ls_dir('../rpmbuild', False)) + shutil.rmtree('../rpmbuild') + + # No patches should be generated if patch-export-rev is upstream version + + # Test patch compression and numbering + eq_(mock_gbp(base_args + ['--git-no-patch-numbers', + '--git-patch-compress=1']), 0) + new_files = ls_dir('../rpmbuild', False) - ref_files + ok_(len(new_files) > 0) + for fname in new_files: + # Patches should start with an alphabet and be compressed with gz + ok_(re.match(r'^[a-zA-Z]\S*.patch.gz$', fname), fname) + + def test_devel_branch_support(self): + """Test patch-generation from q/development branch""" + repo = self.init_test_repo('gbp-test') + repo.rename_branch('srcdata/gbp-test/pq/master', + 'pq/srcdata/gbp-test/master') + pq_br_fmt = 'pq/%(branch)s' + + # Patch export with no apparent pq branch should fail + eq_(mock_gbp(['--git-patch-export']), 2) + self._check_log(-1, r".*Start commit \S+ not an ancestor of end commit") + + # With valid pq branch patch export should succeeded + eq_(mock_gbp(['--git-patch-export', '--git-pq-branch=%s' % pq_br_fmt]), + 0) + self.check_rpms('../rpmbuild/RPMS/*') + shutil.rmtree('../rpmbuild') + eq_(mock_gbp(['--git-patch-export', '--git-pq-branch=%s' % pq_br_fmt, + '--git-export=srcdata/gbp-test/master']), 0) + self.check_rpms('../rpmbuild/RPMS/*') + shutil.rmtree('../rpmbuild') + + # With pq branch but with wrong patch-export rev build should fail + eq_(mock_gbp(['--git-patch-export', '--git-pq-branch=%s' % pq_br_fmt, + '--git-patch-export-rev=HEAD']), 2) + self._check_log(-1, r".*Start commit \S+ not an ancestor of end commit") + + # Patch-export should be auto-enabled when on pq branch + pq_br = pq_br_fmt % {'branch': repo.get_branch()} + repo.set_branch(pq_br) + eq_(mock_gbp(['--git-pq-branch=%s' % pq_br_fmt, '--git-ignore-branch']), + 0) + self.check_rpms('../rpmbuild/RPMS/*') + shutil.rmtree('../rpmbuild') + + # Fail when (apparently) on pq branch but no packaging branch found + eq_(mock_gbp(['--git-pq-branch=%s' % pq_br, '--git-ignore-branch', + '--git-packaging-branch=foo']), 1) +