def test_hotfix_merge_develop(self): """Should build since we need to make sure potential fixes done in hotfix are going to work with the current develop. At this point the configuration version should be the same as in github. """ self.env_vars.ci_env = True self.config.version = '1.1.1' self.env_vars.git_branch = 'refs/heads/develop' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('merge-hotfix-develop.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict( build_tag='0.0.0-develop.b404', is_release=False, is_release_pr=False, is_hotfix_pr=False, workflow=Workflow.git_flow, ), )
def test_invalid_flow(self, read_config_mock, get_branch_mock): config = copy(self.base_config) config.workflow = cast(Workflow, 'oops') get_branch_mock.return_value = Good('master') read_config_mock.return_value = Good(config) res = assert_branch('release', 'm') self.assert_issue(res, 'invalid m workflow')
def test_free_flow(self, read_config_mock, get_branch_mock): get_branch_mock.return_value = Good('master') read_config_mock.return_value = Good(self.base_config) res = assert_branch('release', 'm') self.assert_issue( res, 'The free-flow workflow does not support releases', )
def test_bad_github_response(self): self.env_vars.ci_env = True with patch('m.github.api.graphql') as graphql_mock: graphql_mock.side_effect = [Good({}), Good({})] result = get_git_env(self.config, self.env_vars) err = self.assert_issue(result, 'git_env failure') self.assertEqual( err.cause.message, '`repository` path was not found', )
def test_m_flow_error(self, read_config_mock, get_branch_mock): get_branch_mock.return_value = Good('topic/active-branch') config = copy(self.base_config) config.workflow = Workflow.m_flow read_config_mock.return_value = Good(config) res = assert_branch('release', 'm') self.assert_issue( res, "invalid branch for 'release' using m_flow", )
def test_iteration(self): self.assertListEqual(list(Bad('err').iter()), []) self.assertListEqual(list(Good(100).iter()), [100]) bad = one_of(lambda x: x) left = one_of(lambda: list(Bad('error'))) right = one_of(lambda: list(Good(99))) self.assertIsInstance(bad, Bad) self.assertIsInstance(left, Bad) self.assertIsInstance(right, Good) self.assertEqual(left.value, 'error') self.assertEqual(right.value, 99)
def test_release_pr_no_update(self): """Make sure that the developer updates the version to be greater than the current one in github.""" self.env_vars.ci_env = True self.config.version = '1.1.1' self.env_vars.git_branch = 'refs/pull/2' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('release-pr.json')), ] result = self._get_env() self.assert_issue(result, 'version needs to be bumped')
def test_m_flow(self, read_config_mock, get_branch_mock): get_branch_mock.return_value = Good('master') config = copy(self.base_config) config.workflow = Workflow.m_flow read_config_mock.return_value = Good(config) res = assert_branch('release', 'm') self.assert_ok(res) res = assert_branch('hotfix', 'm') self.assert_ok(res) # different master branch config.m_flow = MFlowConfig('prod') get_branch_mock.return_value = Good('prod') res = assert_branch('release', 'm') self.assert_ok(res)
def test_pass(self): self.env_vars.ci_env = True with patch('m.github.api.graphql') as graphql_mock: graphql_mock.side_effect = [ Good( dict(repository=dict(commit=dict( message='Merge sha1 into sha2', ), ), ), ), Good( dict(repository=dict(commit=dict( oid='123456789', message='commit message', ), ), ), ), ] result = get_git_env(self.config, self.env_vars) self.assertFalse(result.is_bad)
def test_hotfix_merge_random(self): """We should not be merging hotfix branches to random branches.""" self.env_vars.ci_env = True self.config.version = '1.1.2' self.env_vars.git_branch = 'refs/heads/random' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('merge-hotfix-random.json')), ] result = self._get_env() self.assert_issue( result, 'version is ahead (Revert configuration change)', )
def test_pass(self): with patch('m.core.json.read_json') as read_json_mock: read_json_mock.return_value = Good( dict( owner='jmlopez-rod', repo='m', version='0.0.0', workflow='m_flow', ), ) result = read_config('m') config = cast(Config, self.assert_ok(result)) self.assertIsInstance(config, Config) self.assertEqual( { **config.__dict__, **dict( owner='jmlopez-rod', repo='m', version='0.0.0', m_dir='m', workflow=Workflow.m_flow, ), }, config.__dict__, )
def test_pr_1(self): self.env_vars.ci_env = True self.env_vars.git_branch = 'refs/pull/1' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('pr1.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual(result.value.__dict__, dict( build_tag='pr1.b404', is_release=False, is_release_pr=False, is_hotfix_pr=False, workflow=Workflow.free_flow ))
def test_version_ahead(self): """Github says version is 1.1.1 but the config is in 2.0.0. This can be due to a mistake on a developer that bumped the version. """ self.env_vars.ci_env = True self.config.version = '2.0.0' self.env_vars.git_branch = 'refs/heads/my-branch' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('master.json')), ] result = self._get_env() self.assert_issue( result, 'version is ahead (Revert configuration change)', )
def test_master(self): self.env_vars.ci_env = True self.config.version = '1.1.1' self.env_vars.git_branch = 'refs/heads/master' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('master.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict(build_tag='0.0.0-master.b404', is_release=False, is_release_pr=False, is_hotfix_pr=False, workflow=Workflow.m_flow))
def test_master_behind(self): """Github says version is 1.1.1 but the config is still in 0.0.0 This can be fixed by merging the latest. This usually happens when a release gets merged and now the other branches are behind. So this type of error will be a good reminder to developers to update. """ self.env_vars.ci_env = True self.config.version = '0.0.0' self.env_vars.git_branch = 'refs/heads/master' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('master.json')), ] result = self._get_env() self.assert_issue( result, 'version is behind (Branch may need to be updated)')
def test_release_pr_empty_allowed(self): """Empty allowed should allow you to commit any files.""" self.env_vars.ci_env = True self.config.version = '1.1.2' self.env_vars.git_branch = 'refs/pull/2' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('release-pr.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict(build_tag='1.1.2-rc2.b404', is_release=False, is_release_pr=True, is_hotfix_pr=False, workflow=Workflow.m_flow))
def test_release_pr(self): """Make sure that the developer updates the version to be greater than the current one in github.""" self.env_vars.ci_env = True self.config.version = '1.1.2' self.env_vars.git_branch = 'refs/pull/2' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('release-pr.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict(build_tag='1.1.2-rc2.b404', is_release=False, is_release_pr=True, is_hotfix_pr=False, workflow=Workflow.m_flow))
def test_pr_hotfix_no_update_develop(self): self.env_vars.ci_env = True self.config.version = '1.1.1' self.env_vars.git_branch = 'refs/pull/1' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('hotfix-pr-develop.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict( build_tag='SKIP', is_release=False, is_release_pr=False, is_hotfix_pr=True, workflow=Workflow.git_flow, ), )
def test_hotfix_merge(self): """Should use the proper version number.""" self.env_vars.ci_env = True self.config.version = '1.1.2' self.env_vars.git_branch = 'refs/heads/master' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('merge-hotfix.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict( build_tag='1.1.2', is_release=True, is_release_pr=False, is_hotfix_pr=False, workflow=Workflow.git_flow, ), )
def test_release_merge_develop(self): """Need to merge release back into develop and make sure that the build passes.""" self.env_vars.ci_env = True self.config.version = '1.1.1' self.env_vars.git_branch = 'refs/heads/develop' self.env_vars.run_id = '404' with patch('m.core.http.fetch') as graphql_mock: graphql_mock.side_effect = [ Good(mock_commit_sha('sha')), Good(read_fixture('merge-release-develop.json')), ] result = self._get_env() self.assert_ok(result) self.assertEqual( result.value.__dict__, dict( build_tag='0.0.0-develop.b404', is_release=False, is_release_pr=False, is_hotfix_pr=False, workflow=Workflow.git_flow, ), )
def test_empty_config(self): with patch('m.core.json.read_json') as read_json_mock: read_json_mock.return_value = Good({}) result = read_config('m') self.assert_issue(result, 'read_config failure') err = cast(Issue, cast(Issue, result.value).cause) self.assertEqual(err.message, 'multi_get key retrieval failure') if isinstance(err.data, list): msgs = {x['cause']['message'] for x in err.data} self.assertSetEqual( msgs, set([ '`owner` path was not found', '`repo` path was not found', ]), ) else: raise AssertionError('issue data should be a string')
def test_instances(self): left, right = [Bad(False), Good(1)] compare_values(self, [ [left.is_bad, True, '"left" should be Bad(False)'], [right.is_bad, False, '"right" should be Good(1)'], ])