2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::GitRefValidator do
|
2019-06-05 12:25:43 +05:30
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '.validate' do
|
2019-06-05 12:25:43 +05:30
|
|
|
it { expect(described_class.validate('feature/new')).to be true }
|
|
|
|
it { expect(described_class.validate('implement_@all')).to be true }
|
|
|
|
it { expect(described_class.validate('my_new_feature')).to be true }
|
|
|
|
it { expect(described_class.validate('my-branch')).to be true }
|
|
|
|
it { expect(described_class.validate('#1')).to be true }
|
|
|
|
it { expect(described_class.validate('feature/refs/heads/foo')).to be true }
|
|
|
|
it { expect(described_class.validate('feature/~new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/^new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/:new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/?new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/*new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/[new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/new/')).to be false }
|
|
|
|
it { expect(described_class.validate('feature/new.')).to be false }
|
|
|
|
it { expect(described_class.validate('feature\@{')).to be false }
|
|
|
|
it { expect(described_class.validate('feature\new')).to be false }
|
|
|
|
it { expect(described_class.validate('feature//new')).to be false }
|
|
|
|
it { expect(described_class.validate('feature new')).to be false }
|
|
|
|
it { expect(described_class.validate('refs/heads/')).to be false }
|
|
|
|
it { expect(described_class.validate('refs/remotes/')).to be false }
|
|
|
|
it { expect(described_class.validate('refs/heads/feature')).to be false }
|
|
|
|
it { expect(described_class.validate('refs/remotes/origin')).to be false }
|
|
|
|
it { expect(described_class.validate('-')).to be false }
|
|
|
|
it { expect(described_class.validate('-branch')).to be false }
|
|
|
|
it { expect(described_class.validate('+foo:bar')).to be false }
|
|
|
|
it { expect(described_class.validate('foo:bar')).to be false }
|
|
|
|
it { expect(described_class.validate('.tag')).to be false }
|
|
|
|
it { expect(described_class.validate('my branch')).to be false }
|
|
|
|
it { expect(described_class.validate("\xA0\u0000\xB0")).to be false }
|
2023-01-13 00:05:48 +05:30
|
|
|
it { expect(described_class.validate("")).to be false }
|
|
|
|
it { expect(described_class.validate(nil)).to be false }
|
2023-06-20 00:43:36 +05:30
|
|
|
it { expect(described_class.validate('HEAD')).to be false }
|
|
|
|
|
|
|
|
context 'when skip_head_ref_check is true' do
|
|
|
|
it { expect(described_class.validate('HEAD', skip_head_ref_check: true)).to be true }
|
|
|
|
end
|
2019-06-05 12:25:43 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '.validate_merge_request_branch' do
|
2019-06-05 12:25:43 +05:30
|
|
|
it { expect(described_class.validate_merge_request_branch('HEAD')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/new')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('implement_@all')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('my_new_feature')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('my-branch')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('#1')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/refs/heads/foo')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/~new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/^new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/:new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/?new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/*new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/[new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/new/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature/new.')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature\@{')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature\new')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature//new')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('feature new')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('refs/heads/master')).to be true }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('refs/heads/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('refs/remotes/')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('-')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('-branch')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('+foo:bar')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('foo:bar')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('.tag')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch('my branch')).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch("\xA0\u0000\xB0")).to be false }
|
2023-01-13 00:05:48 +05:30
|
|
|
it { expect(described_class.validate_merge_request_branch("")).to be false }
|
|
|
|
it { expect(described_class.validate_merge_request_branch(nil)).to be false }
|
2019-06-05 12:25:43 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|