def test_no_tests_run_if_none_changed(self, write_json_mock): """ Given a git repository with no changes, When burn_in_tests is run, Then no tests are discovered to run. """ variant = "build_variant" repos = [mock_changed_git_files([])] repeat_config = under_test.RepeatConfig() gen_config = under_test.GenerateConfig( variant, "project", ) # yapf: disable mock_evg_conf = MagicMock() mock_evg_conf.get_task_names_by_tag.return_value = set() mock_evg_api = MagicMock() under_test.burn_in("task_id", variant, gen_config, repeat_config, mock_evg_api, mock_evg_conf, repos, "testfile.json") write_json_mock.assert_called_once() written_config = json.loads(write_json_mock.call_args[0][1]) display_task = written_config["buildvariants"][0]["display_tasks"][0] self.assertEqual(1, len(display_task["execution_tasks"])) self.assertEqual(under_test.BURN_IN_TESTS_GEN_TASK, display_task["execution_tasks"][0])
def test_tests_generated_if_a_file_changed(self, write_json_mock): """ Given a git repository with changes, When burn_in_tests is run, Then tests are discovered to run. """ # Note: this test is using actual tests and suites. So changes to those suites could # introduce failures and require this test to be updated. # You can see the test file it is using below. This test is used in the 'auth' and # 'auth_audit' test suites. It needs to be in at least one of those for the test to pass. _config.NAMED_SUITES = None variant = "enterprise-rhel-80-64-bit" repos = [mock_changed_git_files(["jstests/auth/auth1.js"])] repeat_config = under_test.RepeatConfig() gen_config = under_test.GenerateConfig( variant, "project", ) # yapf: disable mock_evg_conf = get_evergreen_config("etc/evergreen.yml") mock_evg_api = MagicMock() under_test.burn_in("task_id", variant, gen_config, repeat_config, mock_evg_api, mock_evg_conf, repos, "testfile.json") write_json_mock.assert_called_once() written_config = json.loads(write_json_mock.call_args[0][1]) n_tasks = len(written_config["tasks"]) # Ensure we are generating at least one task for the test. self.assertGreaterEqual(n_tasks, 1) written_build_variant = written_config["buildvariants"][0] self.assertEqual(variant, written_build_variant["name"]) self.assertEqual(n_tasks, len(written_build_variant["tasks"])) display_task = written_build_variant["display_tasks"][0] # The display task should contain all the generated tasks as well as 1 extra task for # the burn_in_test_gen task. self.assertEqual(n_tasks + 1, len(display_task["execution_tasks"]))