2020-07-02 01:45:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Snippets::RepositoryValidationService do
|
2020-07-02 01:45:43 +05:30
|
|
|
describe '#execute' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:snippet) { create(:personal_snippet, :empty_repo, author: user) }
|
|
|
|
|
|
|
|
let(:repository) { snippet.repository }
|
|
|
|
let(:service) { described_class.new(user, snippet) }
|
|
|
|
|
|
|
|
subject { service.execute }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(repository).to receive(:branch_count).and_return(1)
|
|
|
|
allow(repository).to receive(:ls_files).and_return(['foo'])
|
|
|
|
allow(repository).to receive(:branch_names).and_return(['master'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error when the repository has more than one branch' do
|
|
|
|
allow(repository).to receive(:branch_count).and_return(2)
|
|
|
|
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.message).to match /Repository has more than one branch/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error when existing branch name is not the default one' do
|
|
|
|
allow(repository).to receive(:branch_names).and_return(['foo'])
|
|
|
|
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.message).to match /Repository has an invalid default branch name/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error when the repository has tags' do
|
|
|
|
allow(repository).to receive(:tag_count).and_return(1)
|
|
|
|
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.message).to match /Repository has tags/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error when the repository has more file than the limit' do
|
2021-01-03 14:25:43 +05:30
|
|
|
limit = Snippet.max_file_limit + 1
|
2020-07-02 01:45:43 +05:30
|
|
|
files = Array.new(limit) { FFaker::Filesystem.file_name }
|
|
|
|
allow(repository).to receive(:ls_files).and_return(files)
|
|
|
|
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.message).to match /Repository files count over the limit/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error when the repository has no files' do
|
|
|
|
allow(repository).to receive(:ls_files).and_return([])
|
|
|
|
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.message).to match /Repository must contain at least 1 file/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error when the repository size is over the limit' do
|
2021-01-03 14:25:43 +05:30
|
|
|
expect_next_instance_of(Gitlab::RepositorySizeChecker) do |checker|
|
|
|
|
expect(checker).to receive(:above_size_limit?).and_return(true)
|
|
|
|
end
|
2020-07-02 01:45:43 +05:30
|
|
|
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.message).to match /Repository size is above the limit/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns success when no validation errors are raised' do
|
|
|
|
expect(subject).to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|