Add test facility to add file contents in github tests
In order to do github tests which modify zuul.yaml files we need to specify the content of files as well like in gerrit. Change-Id: I4140d61d16f75879f9b2d4ca21cbde8ba880c2e4
This commit is contained in:
parent
eeb6987df9
commit
3cf229c2d4
|
@ -877,18 +877,17 @@ class FakeGithubPullRequest(object):
|
|||
repo.git.clean('-x', '-f', '-d')
|
||||
|
||||
if files:
|
||||
fn = files[0]
|
||||
self.files = files
|
||||
else:
|
||||
fn = '%s-%s' % (self.branch.replace('/', '_'), self.number)
|
||||
self.files = [fn]
|
||||
self.files = {fn: "test %s %s\n" % (self.branch, self.number)}
|
||||
msg = self.subject + '-' + str(self.number_of_commits)
|
||||
fn = os.path.join(repo.working_dir, fn)
|
||||
f = open(fn, 'w')
|
||||
with open(fn, 'w') as f:
|
||||
f.write("test %s %s\n" %
|
||||
(self.branch, self.number))
|
||||
repo.index.add([fn])
|
||||
for fn, content in self.files.items():
|
||||
fn = os.path.join(repo.working_dir, fn)
|
||||
f = open(fn, 'w')
|
||||
with open(fn, 'w') as f:
|
||||
f.write(content)
|
||||
repo.index.add([fn])
|
||||
|
||||
self.head_sha = repo.index.commit(msg).hexsha
|
||||
# Create an empty set of statuses for the given sha,
|
||||
|
|
|
@ -89,14 +89,14 @@ class TestGithubDriver(ZuulTestCase):
|
|||
def test_pull_matched_file_event(self):
|
||||
A = self.fake_github.openFakePullRequest(
|
||||
'org/project', 'master', 'A',
|
||||
files=['random.txt', 'build-requires'])
|
||||
files={'random.txt': 'test', 'build-requires': 'test'})
|
||||
self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
|
||||
self.waitUntilSettled()
|
||||
self.assertEqual(1, len(self.history))
|
||||
|
||||
# test_pull_unmatched_file_event
|
||||
B = self.fake_github.openFakePullRequest('org/project', 'master', 'B',
|
||||
files=['random.txt'])
|
||||
files={'random.txt': 'test2'})
|
||||
self.fake_github.emitEvent(B.getPullRequestOpenedEvent())
|
||||
self.waitUntilSettled()
|
||||
self.assertEqual(1, len(self.history))
|
||||
|
|
Loading…
Reference in New Issue