Refactor unprotected branch tests
These tests verify behavior by inspecting the unparsed branch cache which we want to remove. Update the tests to verify behavior by examining the actual resulting layout rather than the cache that was used to create that layout. They should work now and in the future despite changes to configloader caching. Change-Id: Ia469865efb1f2d4d9f8f8ef6dc39015ad53e853f
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
name: project-test
|
||||
run: playbooks/project-test.yaml
|
||||
|
||||
- job:
|
||||
name: project1-job
|
||||
|
||||
- project:
|
||||
name: org/project1
|
||||
check:
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
name: used-job
|
||||
run: playbooks/used-job.yaml
|
||||
|
||||
- job:
|
||||
name: project2-job
|
||||
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
|
||||
2
tests/fixtures/config/locked-branches/git/org_project3/zuul.yaml
vendored
Normal file
2
tests/fixtures/config/locked-branches/git/org_project3/zuul.yaml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
- job:
|
||||
name: project3-job
|
||||
@@ -2,6 +2,9 @@
|
||||
name: project-test
|
||||
run: playbooks/project-test.yaml
|
||||
|
||||
- job:
|
||||
name: project1-job
|
||||
|
||||
- project:
|
||||
name: org/project1
|
||||
check:
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
name: used-job
|
||||
run: playbooks/used-job.yaml
|
||||
|
||||
- job:
|
||||
name: project2-job
|
||||
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
name: project-test
|
||||
run: playbooks/project-test.yaml
|
||||
|
||||
- job:
|
||||
name: project1-job
|
||||
|
||||
- project:
|
||||
name: org/project1
|
||||
check:
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
name: used-job
|
||||
run: playbooks/used-job.yaml
|
||||
|
||||
- job:
|
||||
name: project2-job
|
||||
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
|
||||
@@ -1650,20 +1650,14 @@ class TestGithubUnprotectedBranches(ZuulTestCase):
|
||||
scheduler_count = 1
|
||||
|
||||
def test_unprotected_branches(self):
|
||||
tenant = self.scheds.first.sched.abide.tenants\
|
||||
.get('tenant-one')
|
||||
|
||||
project1 = list(tenant.untrusted_projects)[0]
|
||||
project2 = list(tenant.untrusted_projects)[1]
|
||||
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
layout = tenant.layout
|
||||
|
||||
# project1 should have parsed master
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
|
||||
# project2 should have no parsed branch
|
||||
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
|
||||
self.assertNotIn('project2-job', layout.jobs)
|
||||
|
||||
# now enable branch protection and trigger reload
|
||||
github = self.fake_github.getGithubClient()
|
||||
@@ -1676,12 +1670,11 @@ class TestGithubUnprotectedBranches(ZuulTestCase):
|
||||
self.waitUntilSettled()
|
||||
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
layout = tenant.layout
|
||||
|
||||
# project1 and project2 should have parsed master now
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertIn('master', tpc2.parsed_branch_config.keys())
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
self.assertIn('project2-job', layout.jobs)
|
||||
|
||||
def test_filtered_branches_in_build(self):
|
||||
"""
|
||||
@@ -2080,22 +2073,14 @@ class TestGithubLockedBranches(ZuulTestCase):
|
||||
scheduler_count = 1
|
||||
|
||||
def test_exclude_locked_branches(self):
|
||||
tenant = self.scheds.first.sched.abide.tenants\
|
||||
.get('tenant-one')
|
||||
|
||||
project1 = list(tenant.untrusted_projects)[0]
|
||||
project2 = list(tenant.untrusted_projects)[1]
|
||||
project3 = list(tenant.untrusted_projects)[2]
|
||||
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
tpc3 = tenant.project_configs[project3.canonical_name]
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
layout = tenant.layout
|
||||
|
||||
# projects 1 and 2 should have parsed master
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertIn('master', tpc2.parsed_branch_config.keys())
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
self.assertIn('project2-job', layout.jobs)
|
||||
# project 3 should not because it excludes unprotected
|
||||
self.assertEqual(0, len(tpc3.parsed_branch_config.keys()))
|
||||
self.assertNotIn('project3-job', layout.jobs)
|
||||
|
||||
# now lock project2 and trigger reload
|
||||
github = self.fake_github.getGithubClient()
|
||||
@@ -2109,14 +2094,12 @@ class TestGithubLockedBranches(ZuulTestCase):
|
||||
self.waitUntilSettled()
|
||||
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
tpc3 = tenant.project_configs[project3.canonical_name]
|
||||
layout = tenant.layout
|
||||
|
||||
# project2 should no longer have a master branch
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
|
||||
self.assertEqual(0, len(tpc3.parsed_branch_config.keys()))
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
self.assertNotIn('project2-job', layout.jobs)
|
||||
self.assertNotIn('project3-job', layout.jobs)
|
||||
|
||||
# Lock project 3 as well and ensure it's still excluded
|
||||
repo = github.repo_from_project('org/project3')
|
||||
@@ -2129,14 +2112,12 @@ class TestGithubLockedBranches(ZuulTestCase):
|
||||
self.waitUntilSettled()
|
||||
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
tpc3 = tenant.project_configs[project3.canonical_name]
|
||||
layout = tenant.layout
|
||||
|
||||
# project3 is still excluded, but for a different reason
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
|
||||
self.assertEqual(0, len(tpc3.parsed_branch_config.keys()))
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
self.assertNotIn('project2-job', layout.jobs)
|
||||
self.assertNotIn('project3-job', layout.jobs)
|
||||
|
||||
@driver_config('github', branch_protection_rules={
|
||||
'org/project2': {
|
||||
@@ -2148,23 +2129,15 @@ class TestGithubLockedBranches(ZuulTestCase):
|
||||
def test_exclude_locked_branches_startup(self):
|
||||
# Make sure that we exclude locked branches on startup as well
|
||||
# (this exercises a different code path in the branch cache).
|
||||
tenant = self.scheds.first.sched.abide.tenants\
|
||||
.get('tenant-one')
|
||||
|
||||
project1 = list(tenant.untrusted_projects)[0]
|
||||
project2 = list(tenant.untrusted_projects)[1]
|
||||
project3 = list(tenant.untrusted_projects)[2]
|
||||
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
tpc3 = tenant.project_configs[project3.canonical_name]
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
layout = tenant.layout
|
||||
|
||||
# project 1 should have parsed master
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
# project 1 should not have a master branch because it's locked
|
||||
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
# project 2 should not have a master branch because it's locked
|
||||
self.assertNotIn('project2-job', layout.jobs)
|
||||
# project 3 should not because it excludes unprotected
|
||||
self.assertEqual(0, len(tpc3.parsed_branch_config.keys()))
|
||||
self.assertNotIn('project3-job', layout.jobs)
|
||||
|
||||
|
||||
class TestGithubLockedBranchesValidation(ZuulTestCase):
|
||||
|
||||
@@ -1036,20 +1036,14 @@ class TestGitlabUnprotectedBranches(ZuulTestCase):
|
||||
# To make this work with multiple schedulers, we might want to wait
|
||||
# until all schedulers completed their tenant reconfiguration.
|
||||
def test_unprotected_branches(self):
|
||||
tenant = self.scheds.first.sched.abide.tenants\
|
||||
.get('tenant-one')
|
||||
|
||||
project1 = list(tenant.untrusted_projects)[0]
|
||||
project2 = list(tenant.untrusted_projects)[1]
|
||||
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
layout = tenant.layout
|
||||
|
||||
# project1 should have parsed master
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
|
||||
# project2 should have no parsed branch
|
||||
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
|
||||
self.assertNotIn('project2-job', layout.jobs)
|
||||
|
||||
# now enable branch protection and trigger reload
|
||||
self.fake_gitlab.protectBranch('org', 'project2', 'master')
|
||||
@@ -1058,12 +1052,11 @@ class TestGitlabUnprotectedBranches(ZuulTestCase):
|
||||
self.waitUntilSettled()
|
||||
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
tpc1 = tenant.project_configs[project1.canonical_name]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
layout = tenant.layout
|
||||
|
||||
# project1 and project2 should have parsed master now
|
||||
self.assertIn('master', tpc1.parsed_branch_config.keys())
|
||||
self.assertIn('master', tpc2.parsed_branch_config.keys())
|
||||
self.assertIn('project1-job', layout.jobs)
|
||||
self.assertIn('project2-job', layout.jobs)
|
||||
|
||||
def test_filtered_branches_in_build(self):
|
||||
"""
|
||||
|
||||
@@ -4241,12 +4241,10 @@ class TestWebUnprotectedBranches(ZuulTestCase, WebMixin):
|
||||
config errors when no protected branch exists."""
|
||||
self.startWebServer()
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
|
||||
project2 = list(tenant.untrusted_projects)[1]
|
||||
tpc2 = tenant.project_configs[project2.canonical_name]
|
||||
layout = tenant.layout
|
||||
|
||||
# project2 should have no parsed branch
|
||||
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
|
||||
self.assertNotIn('project2-job', layout.jobs)
|
||||
|
||||
# Zuul-web should not display any config errors
|
||||
config_errors = self.get_url(
|
||||
|
||||
Reference in New Issue
Block a user