Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git_ref_validator_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 03dd4e7b89b67dacc421d6bb3b223cda5d926dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GitRefValidator do
  using RSpec::Parameterized::TableSyntax

  describe '.validate' do
    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 }
    it { expect(described_class.validate("")).to be false }
    it { expect(described_class.validate(nil)).to be false }
  end

  describe '.validate_merge_request_branch' do
    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 }
    it { expect(described_class.validate_merge_request_branch("")).to be false }
    it { expect(described_class.validate_merge_request_branch(nil)).to be false }
  end
end