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

random_domain_spec.rb « pages « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 978412bb72cca8da9348d038c693539aa3df9ca1 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Pages::RandomDomain, feature_category: :pages do
  let(:namespace_path) { 'namespace' }

  subject(:generator) do
    described_class.new(project_path: project_path, namespace_path: namespace_path)
  end

  RSpec.shared_examples 'random domain' do |domain|
    it do
      expect(SecureRandom)
        .to receive(:hex)
        .and_wrap_original do |_, size, _|
          ('h' * size)
        end

      generated = generator.generate

      expect(generated).to eq(domain)
      expect(generated.length).to eq(63)
    end
  end

  context 'when project path is less than 48 chars' do
    let(:project_path) { 'p' }

    it_behaves_like 'random domain', 'p-namespace-hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh'
  end

  context 'when project path is close to 48 chars' do
    let(:project_path) { 'p' * 45 }

    it_behaves_like 'random domain', 'ppppppppppppppppppppppppppppppppppppppppppppp-na-hhhhhhhhhhhhhh'
  end

  context 'when project path is larger than 48 chars' do
    let(:project_path) { 'p' * 49 }

    it_behaves_like 'random domain', 'pppppppppppppppppppppppppppppppppppppppppppppppp-hhhhhhhhhhhhhh'
  end
end