From 3ee39f3257da1e5103750039230c50fad886c3fd Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 17 Nov 2016 23:45:07 -0800 Subject: [PATCH] Refactor skip-if tests to use irrelevant-files Skip-if has been removed in favor of irrelevant-files and the branch matchers. This refactors the tests that used to be used for skip-if to cover irrelevant-files. There may still be need to cover the other types of matchers. The 'test_parse_skip_if' has just been removed as it wasn't really covering anything not also covered by the functional tests. Change-Id: I3a4080426c4dc680ed656e18f26597e3d1b7d759 Story: 2000773 Task: 3378 --- .../git/layout-irrelevant-files/zuul.yaml | 27 ++++++++ tests/fixtures/layout-skip-if.yaml | 29 --------- tests/test_scheduler.py | 63 +++++-------------- 3 files changed, 43 insertions(+), 76 deletions(-) create mode 100644 tests/fixtures/config/single-tenant/git/layout-irrelevant-files/zuul.yaml delete mode 100644 tests/fixtures/layout-skip-if.yaml diff --git a/tests/fixtures/config/single-tenant/git/layout-irrelevant-files/zuul.yaml b/tests/fixtures/config/single-tenant/git/layout-irrelevant-files/zuul.yaml new file mode 100644 index 0000000000..f243bccb12 --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-irrelevant-files/zuul.yaml @@ -0,0 +1,27 @@ +- pipeline: + name: check + manager: independent + source: + gerrit + trigger: + gerrit: + - event: patchset-created + success: + gerrit: + verified: 1 + failure: + gerrit: + verified: -1 + + +- job: + name: project-test-irrelevant-files + +- project: + name: org/project + check: + jobs: + - project-test-irrelevant-files: + irrelevant-files: + - ^README$ + - ^ignoreme$ diff --git a/tests/fixtures/layout-skip-if.yaml b/tests/fixtures/layout-skip-if.yaml deleted file mode 100644 index 0cfb445cd9..0000000000 --- a/tests/fixtures/layout-skip-if.yaml +++ /dev/null @@ -1,29 +0,0 @@ -pipelines: - - name: check - manager: IndependentPipelineManager - trigger: - gerrit: - - event: patchset-created - success: - gerrit: - verified: 1 - failure: - gerrit: - verified: -1 - - -jobs: - # Defining a metajob will validate that the skip-if attribute of the - # metajob is correctly copied to the job. - - name: ^.*skip-if$ - skip-if: - - project: ^org/project$ - branch: ^master$ - all-files-match-any: - - ^README$ - - name: project-test-skip-if - -projects: - - name: org/project - check: - - project-test-skip-if diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 328089b6ae..8f27cd93a6 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -20,7 +20,6 @@ import os import re import shutil import time -import yaml from unittest import skip import git @@ -715,37 +714,6 @@ class TestScheduler(ZuulTestCase): self.assertEqual(B.reported, 2) self.assertEqual(C.reported, 2) - @skip("Disabled for early v3 development") - def test_parse_skip_if(self): - job_yaml = """ -jobs: - - name: job_name - skip-if: - - project: ^project_name$ - branch: ^stable/icehouse$ - all-files-match-any: - - ^filename$ - - project: ^project2_name$ - all-files-match-any: - - ^filename2$ - """.strip() - data = yaml.load(job_yaml) - config_job = data.get('jobs')[0] - cm = zuul.change_matcher - expected = cm.MatchAny([ - cm.MatchAll([ - cm.ProjectMatcher('^project_name$'), - cm.BranchMatcher('^stable/icehouse$'), - cm.MatchAllFiles([cm.FileMatcher('^filename$')]), - ]), - cm.MatchAll([ - cm.ProjectMatcher('^project2_name$'), - cm.MatchAllFiles([cm.FileMatcher('^filename2$')]), - ]), - ]) - matcher = self.sched._parseSkipIf(config_job) - self.assertEqual(expected, matcher) - def test_patch_order(self): "Test that dependent patches are tested in the right order" A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') @@ -2234,35 +2202,36 @@ jobs: self.assertEqual(B.data['status'], 'MERGED') self.assertEqual(B.reported, 2) - @skip("Disabled for early v3 development") - def _test_skip_if_jobs(self, branch, should_skip): - "Test that jobs with a skip-if filter run only when appropriate" - self.updateConfigLayout( - 'tests/fixtures/layout-skip-if.yaml') + def _test_irrelevant_files_jobs(self, should_skip): + "Test that jobs with irrelevant-files filter run only when appropriate" + self.updateConfigLayout('layout-irrelevant-files') self.sched.reconfigure(self.config) - self.registerJobs() + + if should_skip: + files = {'ignoreme': 'ignored\n'} + else: + files = {'respectme': 'please!\n'} change = self.fake_gerrit.addFakeChange('org/project', - branch, - 'test skip-if') + 'master', + 'test irrelevant-files', + files=files) self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) self.waitUntilSettled() tested_change_ids = [x.changes[0] for x in self.history - if x.name == 'project-test-skip-if'] + if x.name == 'project-test-irrelevant-files'] if should_skip: self.assertEqual([], tested_change_ids) else: self.assertIn(change.data['number'], tested_change_ids) - @skip("Disabled for early v3 development") - def test_skip_if_match_skips_job(self): - self._test_skip_if_jobs(branch='master', should_skip=True) + def test_irrelevant_files_match_skips_job(self): + self._test_irrelevant_files_jobs(should_skip=True) - @skip("Disabled for early v3 development") - def test_skip_if_no_match_runs_job(self): - self._test_skip_if_jobs(branch='mp', should_skip=False) + def test_irrelevant_files_no_match_runs_job(self): + self._test_irrelevant_files_jobs(should_skip=False) @skip("Disabled for early v3 development") def test_test_config(self):