diff --git a/tests/test_hotfixes.py b/tests/test_hotfixes.py deleted file mode 100644 index 5d0264f..0000000 --- a/tests/test_hotfixes.py +++ /dev/null @@ -1,179 +0,0 @@ -"""Test all scenarios where a hotfix / cherrypick is made.""" -# pylint: disable=too-many-locals,too-many-lines,duplicate-code -import unittest -from unittest import TestCase - -from utils import ActionInputs, ActionOutputs, CommitMessages, TestRepo, run_action, setup_logging - - -class HotfixTestCase(TestCase): - """Test all scenarios where a hotfix / cherrypick is made.""" - repo: TestRepo - - @classmethod - def setUpClass(cls) -> None: - setup_logging() - - def setUp(self) -> None: - self.repo = TestRepo() - - def tearDown(self) -> None: - self.repo.close() - - def test_feature_then_hotfix(self) -> None: - """Test Case: Run the action after a ``feat:`` commit and after a hotfix.""" - # Arrange - # Feature - args_feat_release = ActionInputs( - prefix='v', - suffix='pre', - previous_version_suffix='pre', - create_tag=True - ) - - expected_output_feat_release = ActionOutputs( - version='0.1.0-pre', - version_name='v0.1.0-pre', - previous_version='', - previous_version_name='', - has_changes=True - ) - - args_feat_beta = ActionInputs( - prefix='v', - suffix='beta', - previous_version_suffix='pre', - create_tag=True - ) - - expected_output_feat_beta = ActionOutputs( - version='0.1.0-beta', - version_name='v0.1.0-beta', - previous_version='', - previous_version_name='', - has_changes=True - ) - - args_feat_prod = ActionInputs( - prefix='v', - suffix='', - previous_version_suffix='beta', - create_tag=True - ) - - expected_output_feat_prod = ActionOutputs( - version='0.1.0', - version_name='v0.1.0', - previous_version='', - previous_version_name='', - has_changes=True - ) - - # Hotfix - args_hotfix_release = ActionInputs( - prefix='v', - suffix='pre', - previous_version_suffix='pre', - bumping_suffix='hotfix', - only_bump_suffix=True, - create_tag=True - ) - - expected_output_hotfix_release = ActionOutputs( - version='0.1.0-pre-hotfix.1', - version_name='v0.1.0-pre-hotfix.1', - previous_version='0.1.0-pre', - previous_version_name='v0.1.0-pre', - has_changes=True - ) - - args_hotfix_beta = ActionInputs( - prefix='v', - suffix='beta', - previous_version_suffix='pre', - bumping_suffix='hotfix', - only_bump_suffix=True, - create_tag=True - ) - - expected_output_hotfix_beta = ActionOutputs( - version='0.1.0-beta-hotfix.1', - version_name='v0.1.0-beta-hotfix.1', - previous_version='0.1.0-beta', - previous_version_name='v0.1.0-beta', - has_changes=True - ) - - args_hotfix_prod = ActionInputs( - prefix='v', - suffix='', - previous_version_suffix='beta', - bumping_suffix='hotfix', - only_bump_suffix=True, - create_tag=True - ) - - expected_output_hotfix_prod = ActionOutputs( - version='0.1.0-hotfix.1', - version_name='v0.1.0-hotfix.1', - previous_version='0.1.0', - previous_version_name='v0.1.0', - has_changes=True - ) - - # Act - # Feature - self.repo.commit(CommitMessages.FEATURE) - - self.repo.merge('main', 'release') - actual_output_feat_release = run_action(args_feat_release) - tag_feat_release = self.repo.get_latest_tag_name() - - self.repo.merge('release', 'release-beta') - actual_output_feat_beta = run_action(args_feat_beta) - tag_feat_beta = self.repo.get_latest_tag_name() - - self.repo.merge('release-beta', 'release-prod') - actual_output_feat_prod = run_action(args_feat_prod) - tag_feat_prod = self.repo.get_latest_tag_name() - - # Hotfix - self.repo.checkout('main') - commit = self.repo.commit(CommitMessages.FIX) - - self.repo.cherrypick(commit, 'release') - actual_output_hotfix_release = run_action(args_hotfix_release) - tag_hotfix_release = self.repo.get_latest_tag_name() - - self.repo.cherrypick(commit, 'release-beta') - actual_output_hotfix_beta = run_action(args_hotfix_beta) - tag_hotfix_beta = self.repo.get_latest_tag_name() - - self.repo.cherrypick(commit, 'release-prod') - actual_output_hotfix_prod = run_action(args_hotfix_prod) - tag_hotfix_prod = self.repo.get_latest_tag_name() - - # Assert - # Feature - self.assertEqual(expected_output_feat_release, actual_output_feat_release) - self.assertEqual(expected_output_feat_release.version_name, tag_feat_release) - - self.assertEqual(expected_output_feat_beta, actual_output_feat_beta) - self.assertEqual(expected_output_feat_beta.version_name, tag_feat_beta) - - self.assertEqual(expected_output_feat_prod, actual_output_feat_prod) - self.assertEqual(expected_output_feat_prod.version_name, tag_feat_prod) - - # Hotfix - self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) - self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) - - self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) - self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) - - self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) - self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_one_hotfix.py b/tests/test_one_hotfix.py new file mode 100644 index 0000000..d0d172c --- /dev/null +++ b/tests/test_one_hotfix.py @@ -0,0 +1,487 @@ +"""Test all scenarios where one hotfix / cherrypick is made.""" +# pylint: disable=too-many-locals,too-many-lines,duplicate-code +import unittest +from unittest import TestCase + +from utils import ActionInputs, ActionOutputs, CommitMessages, TestRepo, run_action, setup_logging + + +class OneHotfixTestCase(TestCase): + """Test all scenarios where one hotfix / cherrypick is made.""" + repo: TestRepo + + @classmethod + def setUpClass(cls) -> None: + setup_logging() + + def setUp(self) -> None: + self.repo = TestRepo() + + def tearDown(self) -> None: + self.repo.close() + + def test_fix_then_hotfix(self) -> None: + """Test Case: Run the action after a ``fix:`` commit and after a hotfix.""" + # Arrange + # Fix + args_fix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_fix_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix + args_hotfix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_release = ActionOutputs( + version='0.0.1-pre-hotfix.1', + version_name='v0.0.1-pre-hotfix.1', + previous_version='0.0.1-pre', + previous_version_name='v0.0.1-pre', + has_changes=True + ) + + args_hotfix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_beta = ActionOutputs( + version='0.0.1-beta-hotfix.1', + version_name='v0.0.1-beta-hotfix.1', + previous_version='0.0.1-beta', + previous_version_name='v0.0.1-beta', + has_changes=True + ) + + args_hotfix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_prod = ActionOutputs( + version='0.0.1-hotfix.1', + version_name='v0.0.1-hotfix.1', + previous_version='0.0.1', + previous_version_name='v0.0.1', + has_changes=True + ) + + # Act + # Fix + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_fix_release = run_action(args_fix_release) + tag_fix_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_fix_beta = run_action(args_fix_beta) + tag_fix_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_fix_prod = run_action(args_fix_prod) + tag_fix_prod = self.repo.get_latest_tag_name() + + # Hotfix + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix_release = run_action(args_hotfix_release) + tag_hotfix_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix_beta = run_action(args_hotfix_beta) + tag_hotfix_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix_prod = run_action(args_hotfix_prod) + tag_hotfix_prod = self.repo.get_latest_tag_name() + + # Assert + # Fix + self.assertEqual(expected_output_fix_release, actual_output_fix_release) + self.assertEqual(expected_output_fix_release.version_name, tag_fix_release) + + self.assertEqual(expected_output_fix_beta, actual_output_fix_beta) + self.assertEqual(expected_output_fix_beta.version_name, tag_fix_beta) + + self.assertEqual(expected_output_fix_prod, actual_output_fix_prod) + self.assertEqual(expected_output_fix_prod.version_name, tag_fix_prod) + + # Hotfix + self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) + self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) + + self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) + self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) + + self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) + self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) + + def test_feature_then_hotfix(self) -> None: + """Test Case: Run the action after a ``feat:`` commit and after a hotfix.""" + # Arrange + # Feature + args_feat_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_feat_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_feat_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_feat_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_feat_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_feat_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix + args_hotfix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_release = ActionOutputs( + version='0.1.0-pre-hotfix.1', + version_name='v0.1.0-pre-hotfix.1', + previous_version='0.1.0-pre', + previous_version_name='v0.1.0-pre', + has_changes=True + ) + + args_hotfix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_beta = ActionOutputs( + version='0.1.0-beta-hotfix.1', + version_name='v0.1.0-beta-hotfix.1', + previous_version='0.1.0-beta', + previous_version_name='v0.1.0-beta', + has_changes=True + ) + + args_hotfix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_prod = ActionOutputs( + version='0.1.0-hotfix.1', + version_name='v0.1.0-hotfix.1', + previous_version='0.1.0', + previous_version_name='v0.1.0', + has_changes=True + ) + + # Act + # Feature + self.repo.commit(CommitMessages.FEATURE) + + self.repo.merge('main', 'release') + actual_output_feat_release = run_action(args_feat_release) + tag_feat_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_feat_beta = run_action(args_feat_beta) + tag_feat_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_feat_prod = run_action(args_feat_prod) + tag_feat_prod = self.repo.get_latest_tag_name() + + # Hotfix + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix_release = run_action(args_hotfix_release) + tag_hotfix_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix_beta = run_action(args_hotfix_beta) + tag_hotfix_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix_prod = run_action(args_hotfix_prod) + tag_hotfix_prod = self.repo.get_latest_tag_name() + + # Assert + # Feature + self.assertEqual(expected_output_feat_release, actual_output_feat_release) + self.assertEqual(expected_output_feat_release.version_name, tag_feat_release) + + self.assertEqual(expected_output_feat_beta, actual_output_feat_beta) + self.assertEqual(expected_output_feat_beta.version_name, tag_feat_beta) + + self.assertEqual(expected_output_feat_prod, actual_output_feat_prod) + self.assertEqual(expected_output_feat_prod.version_name, tag_feat_prod) + + # Hotfix + self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) + self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) + + self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) + self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) + + self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) + self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) + + def test_breaking_then_hotfix(self) -> None: + """Test Case: Run the action after a ``feat!:`` commit and after a hotfix.""" + # Arrange + # Breaking + args_breaking_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_breaking_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_breaking_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_breaking_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_breaking_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_breaking_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix + args_hotfix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_release = ActionOutputs( + version='1.0.0-pre-hotfix.1', + version_name='v1.0.0-pre-hotfix.1', + previous_version='1.0.0-pre', + previous_version_name='v1.0.0-pre', + has_changes=True + ) + + args_hotfix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_beta = ActionOutputs( + version='1.0.0-beta-hotfix.1', + version_name='v1.0.0-beta-hotfix.1', + previous_version='1.0.0-beta', + previous_version_name='v1.0.0-beta', + has_changes=True + ) + + args_hotfix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_prod = ActionOutputs( + version='1.0.0-hotfix.1', + version_name='v1.0.0-hotfix.1', + previous_version='1.0.0', + previous_version_name='v1.0.0', + has_changes=True + ) + + # Act + # Breaking + self.repo.commit(CommitMessages.BREAKING_FEATURE) + + self.repo.merge('main', 'release') + actual_output_breaking_release = run_action(args_breaking_release) + tag_breaking_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_breaking_beta = run_action(args_breaking_beta) + tag_breaking_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_breaking_prod = run_action(args_breaking_prod) + tag_breaking_prod = self.repo.get_latest_tag_name() + + # Hotfix + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix_release = run_action(args_hotfix_release) + tag_hotfix_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix_beta = run_action(args_hotfix_beta) + tag_hotfix_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix_prod = run_action(args_hotfix_prod) + tag_hotfix_prod = self.repo.get_latest_tag_name() + + # Assert + # Breaking + self.assertEqual(expected_output_breaking_release, actual_output_breaking_release) + self.assertEqual(expected_output_breaking_release.version_name, tag_breaking_release) + + self.assertEqual(expected_output_breaking_beta, actual_output_breaking_beta) + self.assertEqual(expected_output_breaking_beta.version_name, tag_breaking_beta) + + self.assertEqual(expected_output_breaking_prod, actual_output_breaking_prod) + self.assertEqual(expected_output_breaking_prod.version_name, tag_breaking_prod) + + # Hotfix + self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) + self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) + + self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) + self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) + + self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) + self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_one_hotfix_then_version.py b/tests/test_one_hotfix_then_version.py new file mode 100644 index 0000000..906821f --- /dev/null +++ b/tests/test_one_hotfix_then_version.py @@ -0,0 +1,700 @@ +"""Test all scenarios where one hotfix / cherrypick and a commit with a release after each are made.""" +# pylint: disable=too-many-locals,too-many-lines,duplicate-code +import unittest +from unittest import TestCase + +from utils import ActionInputs, ActionOutputs, CommitMessages, TestRepo, run_action, setup_logging + + +class OneHotfixTestCase(TestCase): + """Test all scenarios where one hotfix / cherrypick and a commit with a release after each are made.""" + repo: TestRepo + + @classmethod + def setUpClass(cls) -> None: + setup_logging() + + def setUp(self) -> None: + self.repo = TestRepo() + + def tearDown(self) -> None: + self.repo.close() + + def test_fix_then_hotfix_then_fix(self) -> None: + """Test Case: Run the action after a ``fix:`` commit, after a hotfix and after another ``fix:`` commit.""" + # Arrange + # Fix 1 + args_fix1_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix1_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix1_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix1_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix1_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_fix1_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix + args_hotfix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_release = ActionOutputs( + version='0.0.1-pre-hotfix.1', + version_name='v0.0.1-pre-hotfix.1', + previous_version='0.0.1-pre', + previous_version_name='v0.0.1-pre', + has_changes=True + ) + + args_hotfix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_beta = ActionOutputs( + version='0.0.1-beta-hotfix.1', + version_name='v0.0.1-beta-hotfix.1', + previous_version='0.0.1-beta', + previous_version_name='v0.0.1-beta', + has_changes=True + ) + + args_hotfix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_prod = ActionOutputs( + version='0.0.1-hotfix.1', + version_name='v0.0.1-hotfix.1', + previous_version='0.0.1', + previous_version_name='v0.0.1', + has_changes=True + ) + + # Fix 2 + args_fix2_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix2_release = ActionOutputs( + version='0.0.2-pre', + version_name='v0.0.2-pre', + previous_version='0.0.1-pre-hotfix.1', + previous_version_name='v0.0.1-pre-hotfix.1', + has_changes=True + ) + + args_fix2_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix2_beta = ActionOutputs( + version='0.0.2-beta', + version_name='v0.0.2-beta', + previous_version='0.0.1-beta-hotfix.1', + previous_version_name='v0.0.1-beta-hotfix.1', + has_changes=True + ) + + args_fix2_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_fix2_prod = ActionOutputs( + version='0.0.2', + version_name='v0.0.2', + previous_version='0.0.1-hotfix.1', + previous_version_name='v0.0.1-hotfix.1', + has_changes=True + ) + + # Act + # Fix 1 + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_fix1_release = run_action(args_fix1_release) + tag_fix1_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_fix1_beta = run_action(args_fix1_beta) + tag_fix1_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_fix1_prod = run_action(args_fix1_prod) + tag_fix1_prod = self.repo.get_latest_tag_name() + + # Hotfix + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix_release = run_action(args_hotfix_release) + tag_hotfix_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix_beta = run_action(args_hotfix_beta) + tag_hotfix_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix_prod = run_action(args_hotfix_prod) + tag_hotfix_prod = self.repo.get_latest_tag_name() + + # Fix 2 + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_fix2_release = run_action(args_fix2_release) + tag_fix2_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_fix2_beta = run_action(args_fix2_beta) + tag_fix2_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_fix2_prod = run_action(args_fix2_prod) + tag_fix2_prod = self.repo.get_latest_tag_name() + + # Assert + # Fix 1 + self.assertEqual(expected_output_fix1_release, actual_output_fix1_release) + self.assertEqual(expected_output_fix1_release.version_name, tag_fix1_release) + + self.assertEqual(expected_output_fix1_beta, actual_output_fix1_beta) + self.assertEqual(expected_output_fix1_beta.version_name, tag_fix1_beta) + + self.assertEqual(expected_output_fix1_prod, actual_output_fix1_prod) + self.assertEqual(expected_output_fix1_prod.version_name, tag_fix1_prod) + + # Hotfix + self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) + self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) + + self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) + self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) + + self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) + self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) + + # Fix 2 + self.assertEqual(expected_output_fix2_release, actual_output_fix2_release) + self.assertEqual(expected_output_fix2_release.version_name, tag_fix2_release) + + self.assertEqual(expected_output_fix2_beta, actual_output_fix2_beta) + self.assertEqual(expected_output_fix2_beta.version_name, tag_fix2_beta) + + self.assertEqual(expected_output_fix2_prod, actual_output_fix2_prod) + self.assertEqual(expected_output_fix2_prod.version_name, tag_fix2_prod) + + def test_fix_then_hotfix_then_feature(self) -> None: + """Test Case: Run the action after a ``fix:`` commit, after a hotfix and after a ``feat:`` commit.""" + # Arrange + # Fix + args_fix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_fix_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix + args_hotfix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_release = ActionOutputs( + version='0.0.1-pre-hotfix.1', + version_name='v0.0.1-pre-hotfix.1', + previous_version='0.0.1-pre', + previous_version_name='v0.0.1-pre', + has_changes=True + ) + + args_hotfix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_beta = ActionOutputs( + version='0.0.1-beta-hotfix.1', + version_name='v0.0.1-beta-hotfix.1', + previous_version='0.0.1-beta', + previous_version_name='v0.0.1-beta', + has_changes=True + ) + + args_hotfix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_prod = ActionOutputs( + version='0.0.1-hotfix.1', + version_name='v0.0.1-hotfix.1', + previous_version='0.0.1', + previous_version_name='v0.0.1', + has_changes=True + ) + + # Feature + args_feature_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_feature_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='0.0.1-pre-hotfix.1', + previous_version_name='v0.0.1-pre-hotfix.1', + has_changes=True + ) + + args_feature_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_feature_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='0.0.1-beta-hotfix.1', + previous_version_name='v0.0.1-beta-hotfix.1', + has_changes=True + ) + + args_feature_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_feature_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='0.0.1-hotfix.1', + previous_version_name='v0.0.1-hotfix.1', + has_changes=True + ) + + # Act + # Fix + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_fix_release = run_action(args_fix_release) + tag_fix_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_fix_beta = run_action(args_fix_beta) + tag_fix_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_fix_prod = run_action(args_fix_prod) + tag_fix_prod = self.repo.get_latest_tag_name() + + # Hotfix + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix_release = run_action(args_hotfix_release) + tag_hotfix_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix_beta = run_action(args_hotfix_beta) + tag_hotfix_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix_prod = run_action(args_hotfix_prod) + tag_hotfix_prod = self.repo.get_latest_tag_name() + + # Feature + self.repo.commit(CommitMessages.FEATURE) + + self.repo.merge('main', 'release') + actual_output_feature_release = run_action(args_feature_release) + tag_feature_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_feature_beta = run_action(args_feature_beta) + tag_feature_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_feature_prod = run_action(args_feature_prod) + tag_feature_prod = self.repo.get_latest_tag_name() + + # Assert + # Fix + self.assertEqual(expected_output_fix_release, actual_output_fix_release) + self.assertEqual(expected_output_fix_release.version_name, tag_fix_release) + + self.assertEqual(expected_output_fix_beta, actual_output_fix_beta) + self.assertEqual(expected_output_fix_beta.version_name, tag_fix_beta) + + self.assertEqual(expected_output_fix_prod, actual_output_fix_prod) + self.assertEqual(expected_output_fix_prod.version_name, tag_fix_prod) + + # Hotfix + self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) + self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) + + self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) + self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) + + self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) + self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) + + # Feature + self.assertEqual(expected_output_feature_release, actual_output_feature_release) + self.assertEqual(expected_output_feature_release.version_name, tag_feature_release) + + self.assertEqual(expected_output_feature_beta, actual_output_feature_beta) + self.assertEqual(expected_output_feature_beta.version_name, tag_feature_beta) + + self.assertEqual(expected_output_feature_prod, actual_output_feature_prod) + self.assertEqual(expected_output_feature_prod.version_name, tag_feature_prod) + + def test_fix_then_hotfix_then_breaking(self) -> None: + """Test Case: Run the action after a ``fix:`` commit, after a hotfix and after a ``feat!`` commit.""" + # Arrange + # Fix + args_fix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_fix_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix + args_hotfix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_release = ActionOutputs( + version='0.0.1-pre-hotfix.1', + version_name='v0.0.1-pre-hotfix.1', + previous_version='0.0.1-pre', + previous_version_name='v0.0.1-pre', + has_changes=True + ) + + args_hotfix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_beta = ActionOutputs( + version='0.0.1-beta-hotfix.1', + version_name='v0.0.1-beta-hotfix.1', + previous_version='0.0.1-beta', + previous_version_name='v0.0.1-beta', + has_changes=True + ) + + args_hotfix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix_prod = ActionOutputs( + version='0.0.1-hotfix.1', + version_name='v0.0.1-hotfix.1', + previous_version='0.0.1', + previous_version_name='v0.0.1', + has_changes=True + ) + + # Breaking + args_breaking_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_breaking_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='0.0.1-pre-hotfix.1', + previous_version_name='v0.0.1-pre-hotfix.1', + has_changes=True + ) + + args_breaking_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_breaking_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='0.0.1-beta-hotfix.1', + previous_version_name='v0.0.1-beta-hotfix.1', + has_changes=True + ) + + args_breaking_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_breaking_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='0.0.1-hotfix.1', + previous_version_name='v0.0.1-hotfix.1', + has_changes=True + ) + + # Act + # Fix + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_fix_release = run_action(args_fix_release) + tag_fix_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_fix_beta = run_action(args_fix_beta) + tag_fix_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_fix_prod = run_action(args_fix_prod) + tag_fix_prod = self.repo.get_latest_tag_name() + + # Hotfix + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix_release = run_action(args_hotfix_release) + tag_hotfix_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix_beta = run_action(args_hotfix_beta) + tag_hotfix_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix_prod = run_action(args_hotfix_prod) + tag_hotfix_prod = self.repo.get_latest_tag_name() + + # Breaking + self.repo.commit(CommitMessages.BREAKING_FEATURE) + + self.repo.merge('main', 'release') + actual_output_breaking_release = run_action(args_breaking_release) + tag_breaking_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_breaking_beta = run_action(args_breaking_beta) + tag_breaking_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_breaking_prod = run_action(args_breaking_prod) + tag_breaking_prod = self.repo.get_latest_tag_name() + + # Assert + # Fix + self.assertEqual(expected_output_fix_release, actual_output_fix_release) + self.assertEqual(expected_output_fix_release.version_name, tag_fix_release) + + self.assertEqual(expected_output_fix_beta, actual_output_fix_beta) + self.assertEqual(expected_output_fix_beta.version_name, tag_fix_beta) + + self.assertEqual(expected_output_fix_prod, actual_output_fix_prod) + self.assertEqual(expected_output_fix_prod.version_name, tag_fix_prod) + + # Hotfix + self.assertEqual(expected_output_hotfix_release, actual_output_hotfix_release) + self.assertEqual(expected_output_hotfix_release.version_name, tag_hotfix_release) + + self.assertEqual(expected_output_hotfix_beta, actual_output_hotfix_beta) + self.assertEqual(expected_output_hotfix_beta.version_name, tag_hotfix_beta) + + self.assertEqual(expected_output_hotfix_prod, actual_output_hotfix_prod) + self.assertEqual(expected_output_hotfix_prod.version_name, tag_hotfix_prod) + + # Breaking + self.assertEqual(expected_output_breaking_release, actual_output_breaking_release) + self.assertEqual(expected_output_breaking_release.version_name, tag_breaking_release) + + self.assertEqual(expected_output_breaking_beta, actual_output_breaking_beta) + self.assertEqual(expected_output_breaking_beta.version_name, tag_breaking_beta) + + self.assertEqual(expected_output_breaking_prod, actual_output_breaking_prod) + self.assertEqual(expected_output_breaking_prod.version_name, tag_breaking_prod) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_two_commits.py b/tests/test_two_commits.py new file mode 100644 index 0000000..8c79f22 --- /dev/null +++ b/tests/test_two_commits.py @@ -0,0 +1,1206 @@ +"""Test all scenarios where two commits with a release at the end are made.""" +# pylint: disable=too-many-locals,too-many-lines,duplicate-code +import unittest +from unittest import TestCase + +from utils import ActionInputs, ActionOutputs, CommitMessages, TestRepo, run_action, setup_logging + + +class TwoCommitsTestCase(TestCase): + """Test all scenarios where two commits with a release at the end are made.""" + repo: TestRepo + + @classmethod + def setUpClass(cls) -> None: + setup_logging() + + def setUp(self) -> None: + self.repo = TestRepo() + + def tearDown(self) -> None: + self.repo.close() + + def test_chore_then_chore(self) -> None: + """Test Case: Run the action after a ``chore:`` and another ``chore:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.0.0-pre', + version_name='v0.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=False + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.0.0-beta', + version_name='v0.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=False + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.0.0', + version_name='v0.0.0', + previous_version='', + previous_version_name='', + has_changes=False + ) + + # Act + self.repo.commit(CommitMessages.CHORE) + self.repo.commit(CommitMessages.CHORE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(None, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(None, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(None, tag_prod) + + def test_chore_then_fix(self) -> None: + """Test Case: Run the action after a ``chore:`` and a ``fix:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.CHORE) + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_chore_then_feat(self) -> None: + """Test Case: Run the action after a ``chore:`` and a ``feat:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.CHORE) + self.repo.commit(CommitMessages.FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_chore_then_breaking(self) -> None: + """Test Case: Run the action after a ``chore:`` and a ``feat!:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.CHORE) + self.repo.commit(CommitMessages.BREAKING_FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_fix_then_chore(self) -> None: + """Test Case: Run the action after a ``fix:`` and a ``chore:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FIX) + self.repo.commit(CommitMessages.CHORE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_fix_then_fix(self) -> None: + """Test Case: Run the action after a ``fix:`` and another ``fix:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FIX) + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_fix_then_feat(self) -> None: + """Test Case: Run the action after a ``fix:`` and a ``feat:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + expected_output_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FIX) + self.repo.commit(CommitMessages.FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_fix_then_breaking(self) -> None: + """Test Case: Run the action after a ``fix:`` and a ``feat!:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FIX) + self.repo.commit(CommitMessages.BREAKING_FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_feat_then_chore(self) -> None: + """Test Case: Run the action after a ``feat:`` and a ``chore:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FEATURE) + self.repo.commit(CommitMessages.CHORE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_feat_then_fix(self) -> None: + """Test Case: Run the action after a ``feat:`` and a ``fix:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FEATURE) + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_feat_then_feat(self) -> None: + """Test Case: Run the action after a ``feat:`` and another ``feat:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + expected_output_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FEATURE) + self.repo.commit(CommitMessages.FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_feat_then_breaking(self) -> None: + """Test Case: Run the action after a ``feat:`` and a ``feat!:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.FEATURE) + self.repo.commit(CommitMessages.BREAKING_FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_breaking_then_chore(self) -> None: + """Test Case: Run the action after a ``feat!:`` and a ``chore:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.BREAKING_FEATURE) + self.repo.commit(CommitMessages.CHORE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_breaking_then_fix(self) -> None: + """Test Case: Run the action after a ``feat!:`` and a ``fix:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.BREAKING_FEATURE) + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_breaking_then_feat(self) -> None: + """Test Case: Run the action after a ``feat!:`` and another ``feat:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.BREAKING_FEATURE) + self.repo.commit(CommitMessages.FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + def test_breaking_then_breaking(self) -> None: + """Test Case: Run the action after a ``feat!:`` and another ``feat!:`` commit.""" + # Arrange + args_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Act + self.repo.commit(CommitMessages.BREAKING_FEATURE) + self.repo.commit(CommitMessages.BREAKING_FEATURE) + + self.repo.merge('main', 'release') + actual_output_release = run_action(args_release) + tag_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_beta = run_action(args_beta) + tag_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_prod = run_action(args_prod) + tag_prod = self.repo.get_latest_tag_name() + + # Assert + self.assertEqual(expected_output_release, actual_output_release) + self.assertEqual(expected_output_release.version_name, tag_release) + + self.assertEqual(expected_output_beta, actual_output_beta) + self.assertEqual(expected_output_beta.version_name, tag_beta) + + self.assertEqual(expected_output_prod, actual_output_prod) + self.assertEqual(expected_output_prod.version_name, tag_prod) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_two_hotfixes.py b/tests/test_two_hotfixes.py new file mode 100644 index 0000000..9f6db70 --- /dev/null +++ b/tests/test_two_hotfixes.py @@ -0,0 +1,721 @@ +"""Test all scenarios where two hotfixes / cherrypicks are made.""" +# pylint: disable=too-many-locals,too-many-lines,duplicate-code +import unittest +from unittest import TestCase + +from utils import ActionInputs, ActionOutputs, CommitMessages, TestRepo, run_action, setup_logging + + +class TwoHotfixesTestCase(TestCase): + """Test all scenarios where two hotfixes / cherrypicks are made.""" + repo: TestRepo + + @classmethod + def setUpClass(cls) -> None: + setup_logging() + + def setUp(self) -> None: + self.repo = TestRepo() + + def tearDown(self) -> None: + self.repo.close() + + def test_fix_then_hotfixes(self) -> None: + """Test Case: Run the action after a ``fix:`` commit and after two hotfixes.""" + # Arrange + # Fix + args_fix_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_release = ActionOutputs( + version='0.0.1-pre', + version_name='v0.0.1-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_fix_beta = ActionOutputs( + version='0.0.1-beta', + version_name='v0.0.1-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_fix_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_fix_prod = ActionOutputs( + version='0.0.1', + version_name='v0.0.1', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix 1 + args_hotfix1_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_release = ActionOutputs( + version='0.0.1-pre-hotfix.1', + version_name='v0.0.1-pre-hotfix.1', + previous_version='0.0.1-pre', + previous_version_name='v0.0.1-pre', + has_changes=True + ) + + args_hotfix1_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_beta = ActionOutputs( + version='0.0.1-beta-hotfix.1', + version_name='v0.0.1-beta-hotfix.1', + previous_version='0.0.1-beta', + previous_version_name='v0.0.1-beta', + has_changes=True + ) + + args_hotfix1_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_prod = ActionOutputs( + version='0.0.1-hotfix.1', + version_name='v0.0.1-hotfix.1', + previous_version='0.0.1', + previous_version_name='v0.0.1', + has_changes=True + ) + + # Hotfix 2 + args_hotfix2_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_release = ActionOutputs( + version='0.0.1-pre-hotfix.2', + version_name='v0.0.1-pre-hotfix.2', + previous_version='0.0.1-pre-hotfix.1', + previous_version_name='v0.0.1-pre-hotfix.1', + has_changes=True + ) + + args_hotfix2_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_beta = ActionOutputs( + version='0.0.1-beta-hotfix.2', + version_name='v0.0.1-beta-hotfix.2', + previous_version='0.0.1-beta-hotfix.1', + previous_version_name='v0.0.1-beta-hotfix.1', + has_changes=True + ) + + args_hotfix2_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_prod = ActionOutputs( + version='0.0.1-hotfix.2', + version_name='v0.0.1-hotfix.2', + previous_version='0.0.1-hotfix.1', + previous_version_name='v0.0.1-hotfix.1', + has_changes=True + ) + + # Act + # Fix + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_fix_release = run_action(args_fix_release) + tag_fix_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_fix_beta = run_action(args_fix_beta) + tag_fix_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_fix_prod = run_action(args_fix_prod) + tag_fix_prod = self.repo.get_latest_tag_name() + + # Hotfix 1 + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix1_release = run_action(args_hotfix1_release) + tag_hotfix1_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix1_beta = run_action(args_hotfix1_beta) + tag_hotfix1_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix1_prod = run_action(args_hotfix1_prod) + tag_hotfix1_prod = self.repo.get_latest_tag_name() + + # Hotfix 2 + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix2_release = run_action(args_hotfix2_release) + tag_hotfix2_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix2_beta = run_action(args_hotfix2_beta) + tag_hotfix2_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix2_prod = run_action(args_hotfix2_prod) + tag_hotfix2_prod = self.repo.get_latest_tag_name() + + # Assert + # Fix + self.assertEqual(expected_output_fix_release, actual_output_fix_release) + self.assertEqual(expected_output_fix_release.version_name, tag_fix_release) + + self.assertEqual(expected_output_fix_beta, actual_output_fix_beta) + self.assertEqual(expected_output_fix_beta.version_name, tag_fix_beta) + + self.assertEqual(expected_output_fix_prod, actual_output_fix_prod) + self.assertEqual(expected_output_fix_prod.version_name, tag_fix_prod) + + # Hotfix 1 + self.assertEqual(expected_output_hotfix1_release, actual_output_hotfix1_release) + self.assertEqual(expected_output_hotfix1_release.version_name, tag_hotfix1_release) + + self.assertEqual(expected_output_hotfix1_beta, actual_output_hotfix1_beta) + self.assertEqual(expected_output_hotfix1_beta.version_name, tag_hotfix1_beta) + + self.assertEqual(expected_output_hotfix1_prod, actual_output_hotfix1_prod) + self.assertEqual(expected_output_hotfix1_prod.version_name, tag_hotfix1_prod) + + # Hotfix 2 + self.assertEqual(expected_output_hotfix2_release, actual_output_hotfix2_release) + self.assertEqual(expected_output_hotfix2_release.version_name, tag_hotfix2_release) + + self.assertEqual(expected_output_hotfix2_beta, actual_output_hotfix2_beta) + self.assertEqual(expected_output_hotfix2_beta.version_name, tag_hotfix2_beta) + + self.assertEqual(expected_output_hotfix2_prod, actual_output_hotfix2_prod) + self.assertEqual(expected_output_hotfix2_prod.version_name, tag_hotfix2_prod) + + def test_feat_then_hotfixes(self) -> None: + """Test Case: Run the action after a ``feat:`` commit and after two hotfixes.""" + # Arrange + # Feature + args_feat_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_feat_release = ActionOutputs( + version='0.1.0-pre', + version_name='v0.1.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_feat_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_feat_beta = ActionOutputs( + version='0.1.0-beta', + version_name='v0.1.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_feat_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_feat_prod = ActionOutputs( + version='0.1.0', + version_name='v0.1.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix 1 + args_hotfix1_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_release = ActionOutputs( + version='0.1.0-pre-hotfix.1', + version_name='v0.1.0-pre-hotfix.1', + previous_version='0.1.0-pre', + previous_version_name='v0.1.0-pre', + has_changes=True + ) + + args_hotfix1_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_beta = ActionOutputs( + version='0.1.0-beta-hotfix.1', + version_name='v0.1.0-beta-hotfix.1', + previous_version='0.1.0-beta', + previous_version_name='v0.1.0-beta', + has_changes=True + ) + + args_hotfix1_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_prod = ActionOutputs( + version='0.1.0-hotfix.1', + version_name='v0.1.0-hotfix.1', + previous_version='0.1.0', + previous_version_name='v0.1.0', + has_changes=True + ) + + # Hotfix 2 + args_hotfix2_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_release = ActionOutputs( + version='0.1.0-pre-hotfix.2', + version_name='v0.1.0-pre-hotfix.2', + previous_version='0.1.0-pre-hotfix.1', + previous_version_name='v0.1.0-pre-hotfix.1', + has_changes=True + ) + + args_hotfix2_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_beta = ActionOutputs( + version='0.1.0-beta-hotfix.2', + version_name='v0.1.0-beta-hotfix.2', + previous_version='0.1.0-beta-hotfix.1', + previous_version_name='v0.1.0-beta-hotfix.1', + has_changes=True + ) + + args_hotfix2_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_prod = ActionOutputs( + version='0.1.0-hotfix.2', + version_name='v0.1.0-hotfix.2', + previous_version='0.1.0-hotfix.1', + previous_version_name='v0.1.0-hotfix.1', + has_changes=True + ) + + # Act + # Feature + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_feat_release = run_action(args_feat_release) + tag_feat_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_feat_beta = run_action(args_feat_beta) + tag_feat_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_feat_prod = run_action(args_feat_prod) + tag_feat_prod = self.repo.get_latest_tag_name() + + # Hotfix 1 + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix1_release = run_action(args_hotfix1_release) + tag_hotfix1_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix1_beta = run_action(args_hotfix1_beta) + tag_hotfix1_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix1_prod = run_action(args_hotfix1_prod) + tag_hotfix1_prod = self.repo.get_latest_tag_name() + + # Hotfix 2 + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix2_release = run_action(args_hotfix2_release) + tag_hotfix2_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix2_beta = run_action(args_hotfix2_beta) + tag_hotfix2_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix2_prod = run_action(args_hotfix2_prod) + tag_hotfix2_prod = self.repo.get_latest_tag_name() + + # Assert + # Feature + self.assertEqual(expected_output_feat_release, actual_output_feat_release) + self.assertEqual(expected_output_feat_release.version_name, tag_feat_release) + + self.assertEqual(expected_output_feat_beta, actual_output_feat_beta) + self.assertEqual(expected_output_feat_beta.version_name, tag_feat_beta) + + self.assertEqual(expected_output_feat_prod, actual_output_feat_prod) + self.assertEqual(expected_output_feat_prod.version_name, tag_feat_prod) + + # Hotfix 1 + self.assertEqual(expected_output_hotfix1_release, actual_output_hotfix1_release) + self.assertEqual(expected_output_hotfix1_release.version_name, tag_hotfix1_release) + + self.assertEqual(expected_output_hotfix1_beta, actual_output_hotfix1_beta) + self.assertEqual(expected_output_hotfix1_beta.version_name, tag_hotfix1_beta) + + self.assertEqual(expected_output_hotfix1_prod, actual_output_hotfix1_prod) + self.assertEqual(expected_output_hotfix1_prod.version_name, tag_hotfix1_prod) + + # Hotfix 2 + self.assertEqual(expected_output_hotfix2_release, actual_output_hotfix2_release) + self.assertEqual(expected_output_hotfix2_release.version_name, tag_hotfix2_release) + + self.assertEqual(expected_output_hotfix2_beta, actual_output_hotfix2_beta) + self.assertEqual(expected_output_hotfix2_beta.version_name, tag_hotfix2_beta) + + self.assertEqual(expected_output_hotfix2_prod, actual_output_hotfix2_prod) + self.assertEqual(expected_output_hotfix2_prod.version_name, tag_hotfix2_prod) + + def test_breaking_then_hotfixes(self) -> None: + """Test Case: Run the action after a ``feat!:`` commit and after two hotfixes.""" + # Arrange + # Breaking + args_breaking_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_breaking_release = ActionOutputs( + version='1.0.0-pre', + version_name='v1.0.0-pre', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_breaking_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + create_tag=True + ) + + expected_output_breaking_beta = ActionOutputs( + version='1.0.0-beta', + version_name='v1.0.0-beta', + previous_version='', + previous_version_name='', + has_changes=True + ) + + args_breaking_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + create_tag=True + ) + + expected_output_breaking_prod = ActionOutputs( + version='1.0.0', + version_name='v1.0.0', + previous_version='', + previous_version_name='', + has_changes=True + ) + + # Hotfix 1 + args_hotfix1_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_release = ActionOutputs( + version='1.0.0-pre-hotfix.1', + version_name='v1.0.0-pre-hotfix.1', + previous_version='1.0.0-pre', + previous_version_name='v1.0.0-pre', + has_changes=True + ) + + args_hotfix1_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_beta = ActionOutputs( + version='1.0.0-beta-hotfix.1', + version_name='v1.0.0-beta-hotfix.1', + previous_version='1.0.0-beta', + previous_version_name='v1.0.0-beta', + has_changes=True + ) + + args_hotfix1_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix1_prod = ActionOutputs( + version='1.0.0-hotfix.1', + version_name='v1.0.0-hotfix.1', + previous_version='1.0.0', + previous_version_name='v1.0.0', + has_changes=True + ) + + # Hotfix 2 + args_hotfix2_release = ActionInputs( + prefix='v', + suffix='pre', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_release = ActionOutputs( + version='1.0.0-pre-hotfix.2', + version_name='v1.0.0-pre-hotfix.2', + previous_version='1.0.0-pre-hotfix.1', + previous_version_name='v1.0.0-pre-hotfix.1', + has_changes=True + ) + + args_hotfix2_beta = ActionInputs( + prefix='v', + suffix='beta', + previous_version_suffix='pre', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_beta = ActionOutputs( + version='1.0.0-beta-hotfix.2', + version_name='v1.0.0-beta-hotfix.2', + previous_version='1.0.0-beta-hotfix.1', + previous_version_name='v1.0.0-beta-hotfix.1', + has_changes=True + ) + + args_hotfix2_prod = ActionInputs( + prefix='v', + suffix='', + previous_version_suffix='beta', + bumping_suffix='hotfix', + only_bump_suffix=True, + create_tag=True + ) + + expected_output_hotfix2_prod = ActionOutputs( + version='1.0.0-hotfix.2', + version_name='v1.0.0-hotfix.2', + previous_version='1.0.0-hotfix.1', + previous_version_name='v1.0.0-hotfix.1', + has_changes=True + ) + + # Act + # Breaking + self.repo.commit(CommitMessages.FIX) + + self.repo.merge('main', 'release') + actual_output_breaking_release = run_action(args_breaking_release) + tag_breaking_release = self.repo.get_latest_tag_name() + + self.repo.merge('release', 'release-beta') + actual_output_breaking_beta = run_action(args_breaking_beta) + tag_breaking_beta = self.repo.get_latest_tag_name() + + self.repo.merge('release-beta', 'release-prod') + actual_output_breaking_prod = run_action(args_breaking_prod) + tag_breaking_prod = self.repo.get_latest_tag_name() + + # Hotfix 1 + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix1_release = run_action(args_hotfix1_release) + tag_hotfix1_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix1_beta = run_action(args_hotfix1_beta) + tag_hotfix1_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix1_prod = run_action(args_hotfix1_prod) + tag_hotfix1_prod = self.repo.get_latest_tag_name() + + # Hotfix 2 + self.repo.checkout('main') + commit = self.repo.commit(CommitMessages.FIX) + + self.repo.cherrypick(commit, 'release') + actual_output_hotfix2_release = run_action(args_hotfix2_release) + tag_hotfix2_release = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-beta') + actual_output_hotfix2_beta = run_action(args_hotfix2_beta) + tag_hotfix2_beta = self.repo.get_latest_tag_name() + + self.repo.cherrypick(commit, 'release-prod') + actual_output_hotfix2_prod = run_action(args_hotfix2_prod) + tag_hotfix2_prod = self.repo.get_latest_tag_name() + + # Assert + # Breaking + self.assertEqual(expected_output_breaking_release, actual_output_breaking_release) + self.assertEqual(expected_output_breaking_release.version_name, tag_breaking_release) + + self.assertEqual(expected_output_breaking_beta, actual_output_breaking_beta) + self.assertEqual(expected_output_breaking_beta.version_name, tag_breaking_beta) + + self.assertEqual(expected_output_breaking_prod, actual_output_breaking_prod) + self.assertEqual(expected_output_breaking_prod.version_name, tag_breaking_prod) + + # Hotfix 1 + self.assertEqual(expected_output_hotfix1_release, actual_output_hotfix1_release) + self.assertEqual(expected_output_hotfix1_release.version_name, tag_hotfix1_release) + + self.assertEqual(expected_output_hotfix1_beta, actual_output_hotfix1_beta) + self.assertEqual(expected_output_hotfix1_beta.version_name, tag_hotfix1_beta) + + self.assertEqual(expected_output_hotfix1_prod, actual_output_hotfix1_prod) + self.assertEqual(expected_output_hotfix1_prod.version_name, tag_hotfix1_prod) + + # Hotfix 2 + self.assertEqual(expected_output_hotfix2_release, actual_output_hotfix2_release) + self.assertEqual(expected_output_hotfix2_release.version_name, tag_hotfix2_release) + + self.assertEqual(expected_output_hotfix2_beta, actual_output_hotfix2_beta) + self.assertEqual(expected_output_hotfix2_beta.version_name, tag_hotfix2_beta) + + self.assertEqual(expected_output_hotfix2_prod, actual_output_hotfix2_prod) + self.assertEqual(expected_output_hotfix2_prod.version_name, tag_hotfix2_prod) + + +if __name__ == '__main__': + unittest.main()