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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2024-01-17 03:08:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-17 03:08:20 +0300
commit3f98f1e47b16b2b1d7a2e8a86252e002c2496098 (patch)
tree197eb008d51c312f3fc06c1e4cd2ecdda69576ea /spec
parentd62742b0169769191b32038cf20445a47db3b287 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/finders/ci/runner_managers_finder_spec.rb32
-rw-r--r--spec/lib/gitlab/github_import/user_finder_spec.rb16
-rw-r--r--spec/lib/gitlab/patch/database_config_spec.rb91
-rw-r--r--spec/requests/api/graphql/ci/runner_spec.rb120
4 files changed, 245 insertions, 14 deletions
diff --git a/spec/finders/ci/runner_managers_finder_spec.rb b/spec/finders/ci/runner_managers_finder_spec.rb
index c62c05d415e..0581330e65b 100644
--- a/spec/finders/ci/runner_managers_finder_spec.rb
+++ b/spec/finders/ci/runner_managers_finder_spec.rb
@@ -65,13 +65,37 @@ RSpec.describe Ci::RunnerManagersFinder, '#execute', feature_category: :fleet_vi
end
end
- context 'without any filters' do
+ describe 'filter by system_id' do
+ let_it_be(:runner_manager1) { create(:ci_runner_machine, runner: runner) }
+ let_it_be(:runner_manager2) { create(:ci_runner_machine, runner: runner) }
+
+ context "when system_id matches runner_manager1's" do
+ let(:params) { { system_id: runner_manager1.system_xid } }
+
+ it { is_expected.to contain_exactly(runner_manager1) }
+ end
+
+ context "when system_id matches runner_manager2's" do
+ let(:params) { { system_id: runner_manager2.system_xid } }
+
+ it { is_expected.to contain_exactly(runner_manager2) }
+ end
+
+ context "when system_id doesn't match" do
+ let(:params) { { system_id: 'non-matching' } }
+
+ it { is_expected.to be_empty }
+ end
+ end
+
+ context 'without any arguments' do
let(:params) { {} }
- let_it_be(:runner_manager) { create(:ci_runner_machine, runner: runner) }
+ let_it_be(:runner_manager1) { create(:ci_runner_machine, runner: runner) }
+ let_it_be(:runner_manager2) { create(:ci_runner_machine, runner: runner) }
- it 'returns all runner managers' do
- expect(runner_managers).to contain_exactly(runner_manager)
+ it 'returns all runner managers in id_desc order' do
+ expect(runner_managers).to eq([runner_manager2, runner_manager1])
end
end
end
diff --git a/spec/lib/gitlab/github_import/user_finder_spec.rb b/spec/lib/gitlab/github_import/user_finder_spec.rb
index 998fa8b2c9f..e3415c12b6f 100644
--- a/spec/lib/gitlab/github_import/user_finder_spec.rb
+++ b/spec/lib/gitlab/github_import/user_finder_spec.rb
@@ -313,6 +313,19 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache, feat
email_for_github_username
end
+ context 'when github_import_lock_user_finder feature flag is disabled' do
+ before do
+ stub_feature_flags(github_import_lock_user_finder: false)
+ end
+
+ it 'does not lock the finder' do
+ expect(finder).not_to receive(:in_lock)
+ expect(client).to receive(:user)
+
+ email_for_github_username
+ end
+ end
+
context 'if the response contains an email' do
before do
allow(client).to receive(:user).and_return({ email: email })
@@ -478,8 +491,9 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache, feat
it 'fetch user detail' do
expect(finder).to receive(:read_email_from_cache).ordered.and_return('')
expect(finder).to receive(:read_email_from_cache).ordered.and_return('')
+ expect(finder).to receive(:read_etag_from_cache).and_return(etag)
expect(finder).to receive(:in_lock).and_yield(true)
- expect(client).to receive(:user).with(username, { headers: {} }).and_return({ email: email }).once
+ expect(client).to receive(:user).with(username, { headers: { 'If-None-Match' => etag } }).once
email_for_github_username
end
diff --git a/spec/lib/gitlab/patch/database_config_spec.rb b/spec/lib/gitlab/patch/database_config_spec.rb
index b06d28dbcd5..73452853050 100644
--- a/spec/lib/gitlab/patch/database_config_spec.rb
+++ b/spec/lib/gitlab/patch/database_config_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::Patch::DatabaseConfig do
expect(Rails::Application::Configuration).to include(described_class)
end
- describe 'config/database.yml' do
+ describe '#database_configuration' do
let(:configuration) { Rails::Application::Configuration.new(Rails.root) }
before do
@@ -68,5 +68,94 @@ RSpec.describe Gitlab::Patch::DatabaseConfig do
end
include_examples 'hash containing main: connection name'
+
+ context 'when config/database.yml contains extra configuration through an external command' do
+ let(:database_yml) do
+ <<-EOS
+ production:
+ config_command: '/opt/database-config.sh'
+ main:
+ adapter: postgresql
+ encoding: unicode
+ database: gitlabhq_production
+ username: git
+ password: "dummy password"
+ host: localhost
+
+ development:
+ config_command: '/opt/database-config.sh'
+ main:
+ adapter: postgresql
+ encoding: unicode
+ database: gitlabhq_development
+ username: postgres
+ password: "dummy password"
+ host: localhost
+ variables:
+ statement_timeout: 15s
+
+ test: &test
+ config_command: '/opt/database-config.sh'
+ main:
+ adapter: postgresql
+ encoding: unicode
+ database: gitlabhq_test
+ username: postgres
+ password:
+ host: localhost
+ prepared_statements: false
+ variables:
+ statement_timeout: 15s
+ EOS
+ end
+
+ context 'when the external command returns valid yaml' do
+ before do
+ allow(Gitlab::Popen)
+ .to receive(:popen)
+ .and_return(["---\nmain:\n password: 'secure password'\n", 0])
+ end
+
+ it 'merges the extra configuration' do
+ database_configuration = configuration.database_configuration
+
+ expect(database_configuration).to match(
+ "production" => { "main" => a_hash_including("password" => "secure password") },
+ "development" => { "main" => a_hash_including("password" => "secure password") },
+ "test" => { "main" => a_hash_including("password" => "secure password") }
+ )
+ end
+ end
+
+ context 'when the external command returns invalid yaml' do
+ before do
+ allow(Gitlab::Popen)
+ .to receive(:popen)
+ .and_return(["---\nmain:\n password: 'secure password\n", 0])
+ end
+
+ it 'raises an error' do
+ expect { configuration.database_configuration }
+ .to raise_error(
+ Gitlab::Patch::DatabaseConfig::CommandExecutionError,
+ %r{database.yml: Execution of `/opt/database-config.sh` generated invalid yaml}
+ )
+ end
+ end
+
+ context 'when the external command fails' do
+ before do
+ allow(Gitlab::Popen).to receive(:popen).and_return(["", 125])
+ end
+
+ it 'raises error' do
+ expect { configuration.database_configuration }
+ .to raise_error(
+ Gitlab::Patch::DatabaseConfig::CommandExecutionError,
+ %r{database.yml: Execution of `/opt/database-config.sh` failed}
+ )
+ end
+ end
+ end
end
end
diff --git a/spec/requests/api/graphql/ci/runner_spec.rb b/spec/requests/api/graphql/ci/runner_spec.rb
index 1b6948d0380..c528100dafa 100644
--- a/spec/requests/api/graphql/ci/runner_spec.rb
+++ b/spec/requests/api/graphql/ci/runner_spec.rb
@@ -213,22 +213,126 @@ RSpec.describe 'Query.runner(id)', :freeze_time, feature_category: :fleet_visibi
end
end
- context 'with build running' do
- let!(:pipeline) { create(:ci_pipeline, project: project1) }
- let!(:runner_manager) do
+ context 'with runner managers' do
+ let_it_be(:runner) { create(:ci_runner) }
+ let_it_be(:runner_manager) do
create(:ci_runner_machine,
runner: runner, ip_address: '127.0.0.1', version: '16.3', revision: 'a', architecture: 'arm', platform: 'osx',
contacted_at: 1.second.ago, executor_type: 'docker')
end
- let!(:runner) { create(:ci_runner) }
- let!(:build) { create(:ci_build, :running, runner: runner, pipeline: pipeline) }
+ describe 'managers' do
+ let_it_be(:runner2) { create(:ci_runner) }
+ let_it_be(:runner_manager2_1) { create(:ci_runner_machine, runner: runner2) }
+ let_it_be(:runner_manager2_2) { create(:ci_runner_machine, runner: runner2) }
+
+ context 'when filtering by status' do
+ let!(:offline_runner_manager) { create(:ci_runner_machine, runner: runner2, contacted_at: 2.hours.ago) }
+ let(:query) do
+ %(
+ query {
+ runner(id: "#{runner2.to_global_id}") {
+ id
+ managers(status: OFFLINE) { nodes { id } }
+ }
+ }
+ )
+ end
- before do
- create(:ci_runner_machine_build, runner_manager: runner_manager, build: build)
+ it 'retrieves expected runner manager' do
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data).to match(a_hash_including(
+ 'runner' => a_graphql_entity_for(
+ 'managers' => {
+ 'nodes' => [a_graphql_entity_for(offline_runner_manager)]
+ }
+ )
+ ))
+ end
+ end
+
+ context 'fetching by runner ID and runner system ID' do
+ let(:query) do
+ %(
+ query {
+ runner1: runner(id: "#{runner.to_global_id}") {
+ id
+ managers(systemId: "#{runner_manager.system_xid}") { nodes { id } }
+ }
+ runner2: runner(id: "#{runner2.to_global_id}") {
+ id
+ managers(systemId: "#{runner_manager2_1.system_xid}") { nodes { id } }
+ }
+ }
+ )
+ end
+
+ it 'retrieves expected runner managers' do
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data).to match(a_hash_including(
+ 'runner1' => a_graphql_entity_for(runner,
+ 'managers' => a_hash_including('nodes' => [a_graphql_entity_for(runner_manager)])),
+ 'runner2' => a_graphql_entity_for(runner2,
+ 'managers' => a_hash_including('nodes' => [a_graphql_entity_for(runner_manager2_1)]))
+ ))
+ end
+ end
+
+ context 'fetching runner ID and all runner managers' do
+ let(:query) do
+ %(
+ query {
+ runner(id: "#{runner2.to_global_id}") { id managers { nodes { id } } }
+ }
+ )
+ end
+
+ it 'retrieves expected runner managers' do
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data).to match(a_hash_including(
+ 'runner' => a_graphql_entity_for(runner2,
+ 'managers' => a_hash_including('nodes' => [
+ a_graphql_entity_for(runner_manager2_2), a_graphql_entity_for(runner_manager2_1)
+ ]))
+ ))
+ end
+ end
+
+ context 'fetching mismatched runner ID and system ID' do
+ let(:query) do
+ %(
+ query {
+ runner(id: "#{runner2.to_global_id}") {
+ id
+ managers(systemId: "#{runner_manager.system_xid}") { nodes { id } }
+ }
+ }
+ )
+ end
+
+ it 'retrieves expected runner managers' do
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data).to match(a_hash_including(
+ 'runner' => a_graphql_entity_for(runner2, 'managers' => a_hash_including('nodes' => []))
+ ))
+ end
+ end
end
- it_behaves_like 'runner details fetch'
+ context 'with build running' do
+ let!(:pipeline) { create(:ci_pipeline, project: project1) }
+ let!(:build) { create(:ci_build, :running, runner: runner, pipeline: pipeline) }
+
+ before do
+ create(:ci_runner_machine_build, runner_manager: runner_manager, build: build)
+ end
+
+ it_behaves_like 'runner details fetch'
+ end
end
end