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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-17 00:07:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-17 00:07:47 +0300
commit2c34e41161b78fddbdff9a858086e95558e06ba0 (patch)
tree7db8b02c06a3ee2319762c9417d37e81397a5d65 /spec/tasks
parent5c4df0629a70c28eb479b513a3e6860e7a35d1c9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/gitlab/metrics_exporter_task_spec.rb81
-rw-r--r--spec/tasks/import_rake_spec.rb110
2 files changed, 191 insertions, 0 deletions
diff --git a/spec/tasks/gitlab/metrics_exporter_task_spec.rb b/spec/tasks/gitlab/metrics_exporter_task_spec.rb
new file mode 100644
index 00000000000..ca37fc1b5d7
--- /dev/null
+++ b/spec/tasks/gitlab/metrics_exporter_task_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+require 'rake_helper'
+require_relative '../../support/helpers/next_instance_of'
+
+RSpec.describe 'gitlab:metrics_exporter:install', feature_category: :metrics do
+ before do
+ Rake.application.rake_require 'tasks/gitlab/metrics_exporter'
+ end
+
+ subject(:task) do
+ Rake::Task['gitlab:metrics_exporter:install']
+ end
+
+ context 'when no target directory is specified' do
+ it 'aborts with an error message' do
+ expect do
+ expect { task.execute }.to output(/Please specify the directory/).to_stdout
+ end.to raise_error(SystemExit)
+ end
+ end
+
+ context 'when target directory is specified' do
+ let(:args) { Rake::TaskArguments.new(%w[dir], %w[path/to/exporter]) }
+ let(:context) { TOPLEVEL_BINDING.eval('self') }
+ let(:expected_clone_params) do
+ {
+ repo: 'https://gitlab.com/gitlab-org/gitlab-metrics-exporter.git',
+ version: an_instance_of(String),
+ target_dir: 'path/to/exporter'
+ }
+ end
+
+ context 'when dependencies are missing' do
+ it 'aborts with an error message' do
+ expect(Gitlab::Utils).to receive(:which).with('gmake').ordered
+ expect(Gitlab::Utils).to receive(:which).with('make').ordered
+
+ expect do
+ expect { task.execute(args) }.to output(/Couldn't find a 'make' binary/).to_stdout
+ end.to raise_error(SystemExit)
+ end
+ end
+
+ it 'installs the exporter with gmake' do
+ expect(Gitlab::Utils).to receive(:which).with('gmake').and_return('path/to/gmake').ordered
+ expect(context).to receive(:checkout_or_clone_version).with(hash_including(expected_clone_params)).ordered
+ expect(Dir).to receive(:chdir).with('path/to/exporter').and_yield.ordered
+ expect(context).to receive(:run_command!).with(['path/to/gmake']).ordered
+
+ task.execute(args)
+ end
+
+ it 'installs the exporter with make' do
+ expect(Gitlab::Utils).to receive(:which).with('gmake').ordered
+ expect(Gitlab::Utils).to receive(:which).with('make').and_return('path/to/make').ordered
+ expect(context).to receive(:checkout_or_clone_version).with(hash_including(expected_clone_params)).ordered
+ expect(Dir).to receive(:chdir).with('path/to/exporter').and_yield.ordered
+ expect(context).to receive(:run_command!).with(['path/to/make']).ordered
+
+ task.execute(args)
+ end
+
+ context 'when overriding version via environment variable' do
+ before do
+ stub_env('GITLAB_METRICS_EXPORTER_VERSION', '1.0')
+ end
+
+ it 'clones from repository with that version instead' do
+ expect(Gitlab::Utils).to receive(:which).with('gmake').and_return('path/to/gmake').ordered
+ expect(context).to receive(:checkout_or_clone_version).with(
+ hash_including(expected_clone_params.merge(version: '1.0'))
+ ).ordered
+ expect(Dir).to receive(:chdir).with('path/to/exporter').and_yield.ordered
+ expect(context).to receive(:run_command!).with(['path/to/gmake']).ordered
+
+ task.execute(args)
+ end
+ end
+ end
+end
diff --git a/spec/tasks/import_rake_spec.rb b/spec/tasks/import_rake_spec.rb
new file mode 100644
index 00000000000..31ce9e124c8
--- /dev/null
+++ b/spec/tasks/import_rake_spec.rb
@@ -0,0 +1,110 @@
+# frozen_string_literal: true
+
+require 'rake_helper'
+
+RSpec.describe 'import:github rake tasks', feature_category: :importers do
+ before do
+ Rake.application.rake_require 'tasks/import'
+ end
+
+ describe ':import' do
+ let(:user) { create(:user) }
+ let(:user_name) { user.username }
+ let(:github_repo) { 'github_user/repo' }
+ let(:target_namespace) { user.namespace_path }
+ let(:project_path) { "#{target_namespace}/project_name" }
+
+ before do
+ allow($stdin).to receive(:getch)
+
+ stub_request(:get, 'https://api.github.com/user/repos?per_page=100')
+ .to_return(
+ status: 200,
+ body: [{ id: 1, full_name: 'github_user/repo', clone_url: 'https://github.com/user/repo.git' }].to_json,
+ headers: { 'Content-Type' => 'application/json' }
+ )
+ end
+
+ context 'when importing a single project' do
+ subject(:import_task) { run_rake_task('import:github', 'token', user_name, project_path, github_repo) }
+
+ context 'when all inputs are correct' do
+ it 'imports a repository' do
+ expect_next_instance_of(Gitlab::GithubImport::SequentialImporter) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ expect_next_instance_of(Project) do |project|
+ expect(project).to receive(:after_import)
+ end
+
+ import_task
+ end
+ end
+
+ context 'when project path is invalid' do
+ let(:project_path) { target_namespace }
+
+ it 'aborts with an error' do
+ expect { import_task }.to raise_error(SystemExit, 'Project path must be: namespace(s)/project_name')
+ end
+ end
+
+ context 'when user is not found' do
+ let(:user_name) { 'unknown_user' }
+
+ it 'aborts with an error' do
+ expect { import_task }.to raise_error("GitLab user #{user_name} not found. Please specify a valid username.")
+ end
+ end
+
+ context 'when github repo is not found' do
+ let(:github_repo) { 'github_user/unknown_repo' }
+
+ it 'aborts with an error' do
+ expect { import_task }.to raise_error('No repo found!')
+ end
+ end
+
+ context 'when namespace to import repo into does not exists' do
+ let(:target_namespace) { 'unknown_namespace_path' }
+
+ it 'aborts with an error' do
+ expect { import_task }.to raise_error('Namespace or group to import repository into does not exist.')
+ end
+ end
+ end
+
+ context 'when importing multiple projects' do
+ subject(:import_task) { run_rake_task('import:github', 'token', user_name, project_path) }
+
+ context 'when user enters github repo id that exists' do
+ before do
+ allow($stdin).to receive(:gets).and_return("1\n")
+ end
+
+ it 'imports a repository' do
+ expect_next_instance_of(Gitlab::GithubImport::SequentialImporter) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ expect_next_instance_of(Project) do |project|
+ expect(project).to receive(:after_import)
+ end
+
+ import_task
+ end
+ end
+
+ context 'when user enters github repo id that does not exists' do
+ before do
+ allow($stdin).to receive(:gets).and_return("2\n")
+ end
+
+ it 'aborts with an error' do
+ expect { import_task }.to raise_error('No repo found!')
+ end
+ end
+ end
+ end
+end