Read about our upcoming Code of Conduct on this issue

Commit 07d87d42 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

HgitalyRepository: Rspec tests for CountDivergingCommits

--HG--
branch : heptapod
parent 7f97345c4674
Pipeline #13765 skipped with stages
......@@ -670,4 +670,66 @@ def blobs_equal?(blob1, blob2)
blob1.send(attr) == blob2.send(attr)
end
end
describe '#diverging_commit_count' do
subject! { non_empty_repository }
def hg_commit(cid, topic: nil)
if topic
subject.hg_call(['topic', topic], user, repository_path, for_write: true)
end
subject.write_file(subject.hg_full_path + "/file#{cid}", "line\n")
subject.hg_call(["add", "file#{cid}"], user, repository_path)
subject.hg_call(['ci', '-m', "Commit #{cid}", '--config',
'experimental.single-head-per-branch=False'],
user, repository_path, for_write: true)
end
let(:prepare_repo) {
subject.hg_call(['up', '0'], user, repository_path)
hg_commit(1, topic: 'feature')
hg_commit(2)
hg_commit(3)
subject.hg_call(['up', '0'], user, repository_path)
hg_commit(4)
hg_commit(5)
}
before do
prepare_repo
end
after do
subject.remove
end
it 'counts 0 for the same branch' do
expect(subject.diverging_commit_count('branch/default', 'branch/default', max_count: 1000)).to eq([0, 0])
# consistency with HgGitRepository
expect(hg_git_repository.diverging_commit_count('branch/default', 'branch/default', max_count: 1000)).to eq([0, 0])
end
context 'max count does not truncate results' do
it 'returns the correct count bounding at max_count' do
expect(subject.diverging_commit_count(
'branch/default', 'topic/default/feature', max_count: 1000
)).to eq([2,3])
# consistency with HgGitRepository
expect(hg_git_repository.diverging_commit_count(
'branch/default', 'topic/default/feature', max_count: 1000
)).to eq([2,3])
end
end
context 'max count truncates results' do
it 'returns the correct count bounding at max_count' do
max_count = 4
resp = subject.diverging_commit_count('branch/default', 'topic/default/feature', max_count: max_count)
expect(resp[0] + resp[1]).to eq(max_count)
# consistency with HgGitRepository
resp = hg_git_repository.diverging_commit_count('branch/default', 'topic/default/feature', max_count: max_count)
expect(resp[0] + resp[1]).to eq(max_count)
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment