2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-20 12:07:52 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Git do
|
2017-03-23 09:08:39 -04:00
|
|
|
let(:committer_email) { 'user@example.org' }
|
|
|
|
let(:committer_name) { 'John Doe' }
|
2016-09-20 12:07:52 -04:00
|
|
|
|
2017-09-12 10:07:31 -04:00
|
|
|
describe '.ref_name' do
|
|
|
|
it 'ensure ref is a valid UTF-8 string' do
|
|
|
|
utf8_invalid_ref = Gitlab::Git::BRANCH_REF_PREFIX + "an_invalid_ref_\xE5"
|
|
|
|
|
|
|
|
expect(described_class.ref_name(utf8_invalid_ref)).to eq("an_invalid_ref_å")
|
|
|
|
end
|
|
|
|
end
|
2017-11-22 09:48:09 -05:00
|
|
|
|
2019-06-13 06:44:41 -04:00
|
|
|
describe '.commit_id?' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:sha, :result) do
|
|
|
|
'' | false
|
|
|
|
'foobar' | false
|
|
|
|
'4b825dc' | false
|
|
|
|
'zzz25dc642cb6eb9a060e54bf8d69288fbee4904' | false
|
|
|
|
|
|
|
|
'4b825dc642cb6eb9a060e54bf8d69288fbee4904' | true
|
|
|
|
Gitlab::Git::BLANK_SHA | true
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns the expected result' do
|
|
|
|
expect(described_class.commit_id?(sha)).to eq(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-22 09:48:09 -05:00
|
|
|
describe '.shas_eql?' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:sha1, :sha2, :result) do
|
|
|
|
sha = RepoHelpers.sample_commit.id
|
|
|
|
short_sha = sha[0, Gitlab::Git::Commit::MIN_SHA_LENGTH]
|
|
|
|
too_short_sha = sha[0, Gitlab::Git::Commit::MIN_SHA_LENGTH - 1]
|
|
|
|
|
|
|
|
[
|
|
|
|
[sha, sha, true],
|
|
|
|
[sha, short_sha, true],
|
|
|
|
[sha, sha.reverse, false],
|
|
|
|
[sha, too_short_sha, false],
|
2019-12-18 10:08:03 -05:00
|
|
|
[sha, nil, false],
|
|
|
|
[nil, nil, true]
|
2017-11-22 09:48:09 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect(described_class.shas_eql?(sha1, sha2)).to eq(result) }
|
|
|
|
it 'is commutative' do
|
|
|
|
expect(described_class.shas_eql?(sha2, sha1)).to eq(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-20 12:07:52 -04:00
|
|
|
end
|