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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/snippets/repository_validation_service_spec.rb')
-rw-r--r--spec/services/snippets/repository_validation_service_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/services/snippets/repository_validation_service_spec.rb b/spec/services/snippets/repository_validation_service_spec.rb
new file mode 100644
index 00000000000..1c139d8c223
--- /dev/null
+++ b/spec/services/snippets/repository_validation_service_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Snippets::RepositoryValidationService do
+ 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
+ limit = Snippet.max_file_limit(user) + 1
+ 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
+ expect_any_instance_of(Gitlab::RepositorySizeChecker).to receive(:above_size_limit?).and_return(true)
+
+ 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