debian-mirror-gitlab/spec/lib/gitlab/pages/random_domain_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.2 KiB
Ruby
Raw Normal View History

2023-05-27 22:25:52 +05:30
# 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