summaryrefslogtreecommitdiff
path: root/spec/finders/packages/go/module_finder_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/finders/packages/go/module_finder_spec.rb')
-rw-r--r--spec/finders/packages/go/module_finder_spec.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/finders/packages/go/module_finder_spec.rb b/spec/finders/packages/go/module_finder_spec.rb
new file mode 100644
index 00000000000..e5c8827fc8d
--- /dev/null
+++ b/spec/finders/packages/go/module_finder_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Packages::Go::ModuleFinder do
+ let_it_be(:project) { create :project }
+ let_it_be(:other_project) { create :project }
+ let(:finder) { described_class.new project, module_name }
+
+ shared_examples 'an invalid path' do
+ describe '#module_name' do
+ it 'returns the expected name' do
+ expect(finder.module_name).to eq(expected_name)
+ end
+ end
+
+ describe '#execute' do
+ it 'returns nil' do
+ expect(finder.execute).to be_nil
+ end
+ end
+ end
+
+ describe '#execute' do
+ context 'with module name equal to project name' do
+ let(:module_name) { base_url(project) }
+
+ it 'returns a module with empty path' do
+ mod = finder.execute
+ expect(mod).not_to be_nil
+ expect(mod.path).to eq('')
+ end
+ end
+
+ context 'with module name starting with project name and slash' do
+ let(:module_name) { base_url(project) + '/mod' }
+
+ it 'returns a module with non-empty path' do
+ mod = finder.execute
+ expect(mod).not_to be_nil
+ expect(mod.path).to eq('mod')
+ end
+ end
+
+ context 'with a module name not equal to and not starting with project name' do
+ let(:module_name) { base_url(other_project) }
+
+ it 'returns nil' do
+ expect(finder.execute).to be_nil
+ end
+ end
+ end
+
+ context 'with relative path component' do
+ it_behaves_like 'an invalid path' do
+ let(:module_name) { base_url(project) + '/../xyz' }
+ let(:expected_name) { base_url(project.namespace) + '/xyz' }
+ end
+ end
+
+ context 'with many relative path components' do
+ it_behaves_like 'an invalid path' do
+ let(:module_name) { base_url(project) + ('/..' * 10) + '/xyz' }
+ let(:expected_name) { ('../' * 7) + 'xyz' }
+ end
+ end
+
+ def base_url(project)
+ "#{Settings.build_gitlab_go_url}/#{project.full_path}"
+ end
+end