2010-05-24 00:56:30 -03:00
|
|
|
#
|
2010-05-24 11:26:22 -03:00
|
|
|
# Copyright (c) 2008-2010 Red Hat, Inc.
|
2010-05-24 00:56:30 -03:00
|
|
|
#
|
|
|
|
# This software is licensed to you under the GNU General Public License,
|
|
|
|
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
|
|
|
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
|
|
|
# along with this software; if not, see
|
|
|
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
|
|
|
#
|
|
|
|
# Red Hat trademarks are not licensed under GPLv2. No permission is
|
|
|
|
# granted to use or replicate Red Hat trademarks that are incorporated
|
|
|
|
# in this software or its documentation.
|
|
|
|
|
|
|
|
import os
|
2015-05-08 10:58:56 -04:00
|
|
|
from tito.builder import Builder, UpstreamBuilder
|
|
|
|
from tito.common import tag_exists_locally, check_tag_exists
|
2014-05-19 22:39:24 +01:00
|
|
|
from tito.release import Releaser
|
2014-11-24 18:49:29 +01:00
|
|
|
from tito.compat import getoutput
|
2014-02-22 19:43:43 +00:00
|
|
|
from functional.fixture import TitoGitTestFixture, tito
|
2015-05-08 13:05:38 -03:00
|
|
|
from tito.compat import RawConfigParser
|
2016-05-26 15:00:39 +02:00
|
|
|
from unit import Capture
|
2010-05-24 00:56:30 -03:00
|
|
|
|
2010-05-24 11:26:22 -03:00
|
|
|
PKG_NAME = "titotestpkg"
|
2010-05-24 00:56:30 -03:00
|
|
|
|
|
|
|
|
2010-05-24 11:26:22 -03:00
|
|
|
class SingleProjectTests(TitoGitTestFixture):
|
2010-05-24 00:56:30 -03:00
|
|
|
|
|
|
|
def setUp(self):
|
2010-05-24 11:26:22 -03:00
|
|
|
TitoGitTestFixture.setUp(self)
|
2010-05-24 00:56:30 -03:00
|
|
|
|
2010-05-24 14:59:50 -03:00
|
|
|
self.create_project(PKG_NAME)
|
2010-05-24 00:56:30 -03:00
|
|
|
os.chdir(self.repo_dir)
|
|
|
|
|
2014-05-19 22:39:24 +01:00
|
|
|
self.config = RawConfigParser()
|
|
|
|
self.config.add_section("buildconfig")
|
|
|
|
self.config.set("buildconfig", "builder", "tito.builder.Builder")
|
|
|
|
self.config.set("buildconfig", "offline", "true")
|
|
|
|
|
|
|
|
self.releaser_config = RawConfigParser()
|
|
|
|
self.releaser_config.add_section('test')
|
|
|
|
self.releaser_config.set('test', 'releaser',
|
|
|
|
'tito.release.Releaser')
|
|
|
|
|
2010-05-24 00:56:30 -03:00
|
|
|
def test_init_worked(self):
|
2011-11-25 11:30:51 -04:00
|
|
|
# Not actually running init here, just making sure it worked when
|
2010-05-24 00:56:30 -03:00
|
|
|
# run during setup.
|
2015-04-26 14:10:11 +02:00
|
|
|
self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito")))
|
|
|
|
self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
|
2010-05-24 00:56:30 -03:00
|
|
|
"packages")))
|
2015-04-26 14:10:11 +02:00
|
|
|
self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
|
2010-05-24 00:56:30 -03:00
|
|
|
"tito.props")))
|
|
|
|
|
2010-05-24 11:26:22 -03:00
|
|
|
def test_initial_tag(self):
|
|
|
|
self.assertTrue(tag_exists_locally("%s-0.0.1-1" % PKG_NAME))
|
|
|
|
|
2010-05-24 11:35:07 -03:00
|
|
|
def test_tag(self):
|
|
|
|
tito("tag --accept-auto-changelog --debug")
|
|
|
|
check_tag_exists("%s-0.0.2-1" % PKG_NAME, offline=True)
|
|
|
|
|
2011-10-21 16:23:01 -04:00
|
|
|
def test_tag_with_version(self):
|
|
|
|
tito("tag --accept-auto-changelog --debug --use-version 9.0.0")
|
|
|
|
check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)
|
|
|
|
|
2016-11-29 15:46:52 -05:00
|
|
|
def test_tag_with_release(self):
|
|
|
|
tito("tag --accept-auto-changelog --debug --use-release dummyvalue")
|
|
|
|
check_tag_exists("%s-0.0.2-dummyvalue" % PKG_NAME, offline=True)
|
|
|
|
|
|
|
|
def test_tag_with_version_and_release(self):
|
|
|
|
tito("tag --accept-auto-changelog --debug --use-version 9.0.0 --use-release dummyvalue")
|
|
|
|
check_tag_exists("%s-9.0.0-dummyvalue" % PKG_NAME, offline=True)
|
|
|
|
|
2016-03-30 21:03:15 -04:00
|
|
|
def test_tag_with_changelog(self):
|
|
|
|
tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog='-Test'")
|
|
|
|
check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)
|
|
|
|
|
|
|
|
changelog = getoutput("cat *.spec")
|
|
|
|
self.assertTrue('-Test' in changelog)
|
|
|
|
|
|
|
|
def test_tag_with_changelog_format(self):
|
|
|
|
tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test")
|
|
|
|
check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)
|
|
|
|
|
|
|
|
changelog = getoutput("cat *.spec")
|
|
|
|
self.assertTrue('- Test' in changelog)
|
|
|
|
|
|
|
|
def test_tag_with_changelog_multiple(self):
|
|
|
|
tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test --changelog=Fake")
|
|
|
|
check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)
|
|
|
|
|
|
|
|
changelog = getoutput("cat *.spec")
|
|
|
|
self.assertTrue('- Test' in changelog)
|
|
|
|
self.assertTrue('- Fake' in changelog)
|
|
|
|
|
2010-05-24 11:35:07 -03:00
|
|
|
def test_undo_tag(self):
|
2014-03-08 22:25:35 +00:00
|
|
|
os.chdir(self.repo_dir)
|
|
|
|
original_head = getoutput('git show-ref -s refs/heads/master')
|
|
|
|
|
|
|
|
# Create tito tag, which adds a new commit and moves head.
|
2010-05-24 11:35:07 -03:00
|
|
|
tito("tag --accept-auto-changelog --debug")
|
|
|
|
tag = "%s-0.0.2-1" % PKG_NAME
|
|
|
|
check_tag_exists(tag, offline=True)
|
2014-03-08 22:25:35 +00:00
|
|
|
new_head = getoutput('git show-ref -s refs/heads/master')
|
|
|
|
self.assertNotEqual(original_head, new_head)
|
|
|
|
|
|
|
|
# Undo tito tag, which rewinds one commit to original head.
|
2010-05-24 11:35:07 -03:00
|
|
|
tito("tag -u")
|
|
|
|
self.assertFalse(tag_exists_locally(tag))
|
2014-03-08 22:25:35 +00:00
|
|
|
new_head = getoutput('git show-ref -s refs/heads/master')
|
|
|
|
self.assertEqual(original_head, new_head)
|
2010-05-24 11:35:07 -03:00
|
|
|
|
2016-05-26 15:00:39 +02:00
|
|
|
def test_tag_with_custom_message(self):
|
|
|
|
os.chdir(self.repo_dir)
|
|
|
|
with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f:
|
|
|
|
f.write('tag_commit_message_format = No info plz\n')
|
|
|
|
|
|
|
|
tito("tag --accept-auto-changelog")
|
|
|
|
|
|
|
|
last_msg = getoutput('git log -n 1 --pretty=format:%s')
|
|
|
|
self.assertEqual('No info plz', last_msg.strip())
|
|
|
|
|
|
|
|
def test_tag_with_custom_message_bad_placeholder(self):
|
|
|
|
os.chdir(self.repo_dir)
|
|
|
|
with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f:
|
|
|
|
f.write('tag_commit_message_format = %(ultimate_answer)s\n')
|
|
|
|
|
|
|
|
with Capture(silent=True) as capture:
|
|
|
|
self.assertRaises(SystemExit, tito, "tag --accept-auto-changelog")
|
2017-01-26 15:52:02 -05:00
|
|
|
self.assertTrue("Unknown placeholder 'ultimate_answer' in tag_commit_message_format" in
|
2016-05-26 15:00:39 +02:00
|
|
|
capture.err)
|
|
|
|
|
|
|
|
def test_tag_with_custom_message_containing_quotes(self):
|
|
|
|
os.chdir(self.repo_dir)
|
|
|
|
with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f:
|
|
|
|
f.write('tag_commit_message_format = Hack"%(name)s\\\n')
|
|
|
|
|
|
|
|
tito("tag --accept-auto-changelog")
|
|
|
|
|
|
|
|
last_msg = getoutput('git log -n 1 --pretty=format:%s')
|
|
|
|
self.assertEqual('Hack"titotestpkg\\', last_msg.strip())
|
|
|
|
|
2010-05-24 11:26:22 -03:00
|
|
|
def test_latest_tgz(self):
|
|
|
|
tito("build --tgz -o %s" % self.repo_dir)
|
|
|
|
|
2014-01-10 15:49:49 -04:00
|
|
|
def test_build_tgz_tag(self):
|
2010-05-24 11:26:22 -03:00
|
|
|
tito("build --tgz --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
|
|
|
|
self.repo_dir))
|
2011-11-25 11:30:51 -04:00
|
|
|
self.assertTrue(os.path.exists(os.path.join(self.repo_dir,
|
2010-05-24 11:26:22 -03:00
|
|
|
"%s-0.0.1.tar.gz" % PKG_NAME)))
|
|
|
|
|
2014-01-10 15:49:49 -04:00
|
|
|
def test_build_latest_srpm(self):
|
2010-05-24 11:26:22 -03:00
|
|
|
tito("build --srpm")
|
|
|
|
|
2014-01-10 15:49:49 -04:00
|
|
|
def test_build_srpm_tag(self):
|
2011-11-25 11:30:51 -04:00
|
|
|
tito("build --srpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME, self.repo_dir))
|
2010-05-24 11:26:22 -03:00
|
|
|
|
2014-01-10 15:49:49 -04:00
|
|
|
def test_build_latest_rpm(self):
|
2010-05-24 11:26:22 -03:00
|
|
|
tito("build --rpm -o %s" % self.repo_dir)
|
|
|
|
|
2014-01-10 15:49:49 -04:00
|
|
|
def test_build_rpm_tag(self):
|
2011-11-25 11:30:51 -04:00
|
|
|
tito("build --rpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
|
2010-05-24 11:26:22 -03:00
|
|
|
self.repo_dir))
|
2014-05-19 22:39:24 +01:00
|
|
|
|
|
|
|
def test_release(self):
|
|
|
|
releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
|
|
|
|
self.config, {}, 'test', self.releaser_config, False,
|
|
|
|
False, False, **{'offline': True})
|
|
|
|
self.assertTrue(isinstance(releaser.builder, Builder))
|
|
|
|
releaser.release(dry_run=True)
|
|
|
|
|
|
|
|
def test_release_override_builder(self):
|
|
|
|
self.releaser_config.set('test', 'builder',
|
|
|
|
'tito.builder.UpstreamBuilder')
|
|
|
|
releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
|
|
|
|
self.config, {}, 'test', self.releaser_config, False,
|
|
|
|
False, False, **{'offline': True})
|
|
|
|
self.assertTrue(isinstance(releaser.builder,
|
|
|
|
UpstreamBuilder))
|
|
|
|
releaser.release(dry_run=True)
|