#!/usr/bin/env python3 # type: ignore import unittest from ci import CiOptions from ci_config import JobNames _TEST_BODY_1 = """ #### Run only: - [x] Integration tests - [ ] Integration tests (arm64) - [x] Integration tests - [x] Integration tests - [ ] Integration tests - [x] some invalid mask - should be skipped - [x] Integration tests - [ ] Integration tests #### CI options: - [ ] do not test (only style check) - [x] disable merge-commit (no merge from master before tests) - [ ] disable CI cache (job reuse) #### Only specified batches in multi-batch jobs: - [x] 1 - [ ] 2 """ _TEST_BODY_2 = """ - [x] MUST include integration tests - [x] MUST include stateless tests - [x] no action must be applied - [ ] no action must be applied - [x] MUST exclude tsan - [x] MUST exclude aarch64 - [x] MUST exclude test with analazer - [ ] no action applied - [x] Must exclude statless test with s3 storage - [x] Must exclude tests on coverage build """ _TEST_BODY_3 = """ - [x] Must include all tests for analyzer """ class TestCIOptions(unittest.TestCase): def test_pr_body_parsing(self): ci_options = CiOptions.create_from_pr_message( _TEST_BODY_1, update_from_api=False ) self.assertFalse(ci_options.do_not_test) self.assertFalse(ci_options.no_ci_cache) self.assertTrue(ci_options.no_merge_commit) self.assertEqual(ci_options.ci_sets, ["ci_set_integration"]) self.assertCountEqual(ci_options.include_keywords, ["foo", "foo_bar"]) self.assertCountEqual(ci_options.exclude_keywords, ["foo", "foo_bar"]) def test_options_applied(self): self.maxDiff = None ci_options = CiOptions.create_from_pr_message( _TEST_BODY_2, update_from_api=False ) self.assertCountEqual( ci_options.include_keywords, ["integration", "foo_bar", "stateless"] ) self.assertCountEqual( ci_options.exclude_keywords, ["tsan", "aarch64", "analyzer", "s3_storage", "coverage"], ) jobs_to_do = list(JobNames) jobs_to_skip = [] job_params = {} jobs_to_do, jobs_to_skip, job_params = ci_options.apply( jobs_to_do, jobs_to_skip, job_params ) self.assertCountEqual( jobs_to_do, [ "Style check", "package_release", "package_asan", "package_ubsan", "package_debug", "package_msan", "Stateless tests (asan)", "Stateless tests flaky check (asan)", "Stateless tests (msan)", "Stateless tests (ubsan)", "Stateless tests (debug)", "Stateless tests (release)", "Integration tests (release)", "Integration tests (asan)", "Integration tests flaky check (asan)", ], ) def test_options_applied_2(self): self.maxDiff = None ci_options = CiOptions.create_from_pr_message( _TEST_BODY_3, update_from_api=False ) self.assertCountEqual(ci_options.include_keywords, ["analyzer"]) self.assertIsNone(ci_options.exclude_keywords) jobs_to_do = list(JobNames) jobs_to_skip = [] job_params = {} jobs_to_do, jobs_to_skip, job_params = ci_options.apply( jobs_to_do, jobs_to_skip, job_params ) self.assertCountEqual( jobs_to_do, [ "Style check", "Integration tests (asan, old analyzer)", "package_release", "Stateless tests (release, old analyzer, s3, DatabaseReplicated)", "package_asan", ], )