Commit 524d82a6 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨

hgitaly_commit: add Rspec tests for #find_all

--HG--
branch : heptapod-stable
parent a97f809fcb20
# frozen_string_literal: true
require "spec_helper"
# rubocop:disable RSpec/FilePath
RSpec.describe Gitlab::Git::Commit, :seed_helper do
include Gitlab::EncodingHelper
include RepoHelpers
include Gitlab::Popen
def hg_commit(repo, file, date: nil, par: nil, branch: nil)
date = '0 0' if date.nil?
repo.hg_call(['up', par], user, repository_path) unless par.nil?
unless branch.nil?
repo.hg_call(['branch', "#{branch}"], user,
repository_path, for_write: true)
end
repo.write_file(repo.hg_full_path + "/#{file}",
"I am a line in file '#{file}'\n")
repo.hg_call(['add', "#{file}"], user, repository_path)
repo.hg_call(['ci', '-m', "Commit #{file}", '--config',
'experimental.single-head-per-branch=False',
'-d', "#{date}"],
user, repository_path, for_write: true)
repo.hgsha_from_rev('.', repository_path)
end
before do
stub_const('HGITALY_TEST_REPO_PATH', 'hgitaly-repo.git')
end
let(:repository) do
repo = Gitlab::Mercurial::HgitalyRepository.new('default', HGITALY_TEST_REPO_PATH, '', 'group/project')
repo.unit_tests_skip_hooks = true
repo
end
# Same repository as :repository, seen as HgGitRepository, so that
#
# 1. we can use HgGitRepository as a reference for assertions on method
# results
# 2. we have easy fixture preparation options
let(:hg_git_repository) do
repo = Gitlab::Mercurial::HgGitRepository.new('default', HGITALY_TEST_REPO_PATH, '', 'group/project')
repo.unit_tests_skip_hooks = true
repo
end
let(:repository_path) { File.join(TestEnv.repos_path, repository.relative_path).chomp('.git') + '.hg' }
let(:user) { build(:user) }
let(:non_empty_repository) do
status = hg_git_repository.create_repository(namespace_fs_path: "group",
in_subgroup: false)
expect(status).to be(true)
hg_commit(hg_git_repository, 'foo', date: "0 0")
repository # HgitalyRepository
end
let(:non_empty_repository_path) { repository_path }
describe '#find_all' do
subject! { non_empty_repository }
before do
prepare_repo
end
after do
subject.remove
end
def hgsha(rev)
subject.hgsha_from_rev(rev)
end
def gitsha(sha)
hg_git_repository.hg_git_invalidate_maps!
hg_git_repository.sha_from_hgsha(sha)
end
# repo structure:
#
# o changeset: 2: Commit bar
# |
# | o changeset: 1: Commit car (branch: stable)
# |/
# o changeset: 0: Commit foo
#
let!(:offset) { 86400 } # seconds in 24 hours
let(:prepare_repo) {
hg_commit(subject, 'car', par: '0', branch: 'stable',
date: "#{offset} 0")
hg_commit(subject, 'bar', par: '0', date: "#{offset * 2} 0")
}
let(:hgsha_0) { hgsha('0') }
let(:hgsha_1) { hgsha('1') }
let(:hgsha_2) { hgsha('2') }
let(:gitsha_0) { gitsha(hgsha_0) }
let(:gitsha_1) { gitsha(hgsha_1) }
let(:gitsha_2) { gitsha(hgsha_2) }
it 'returns a collection of commits' do
commits = described_class.find_all(subject).map(&:id)
expect(commits).to eq([hgsha_2, hgsha_1, hgsha_0])
# consistency with HgGitRepository
commits = described_class.find_all(hg_git_repository).map(&:id)
expect(commits).to eq([gitsha_2, gitsha_1, gitsha_0])
end
context 'max_count' do
it 'return maximum max_count number of commits' do
commits = described_class.find_all(subject, max_count: 2).map(&:id)
expect(commits).to eq([hgsha_2, hgsha_1])
# consistency with HgGitRepository
commits = described_class.find_all(hg_git_repository, max_count: 2).map(&:id)
expect(commits).to eq([gitsha_2, gitsha_1])
end
end
context 'ref + max_count + skip' do
it 'returns a collection of commits' do
commits = described_class.find_all(
subject,
ref: 'branch/default',
max_count: 1,
skip: 1
).map(&:id)
expect(commits).to eq([hgsha_0])
# consistency with HgGitRepository
commits = described_class.find_all(
hg_git_repository,
ref: 'branch/default',
max_count: 1,
skip: 1
).map(&:id)
expect(commits).to eq([gitsha_0])
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