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>2021-05-18 12:10:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-18 12:10:37 +0300
commitac70f62e33c37970180e706906a8ce538155c9c5 (patch)
tree32624f461169b323a246ba15e1782e55b81afece /spec
parent5b63a652d1e07996101c2ce147da4a9eea6c89e1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/graphql/resolvers/ci/runners_resolver_spec.rb136
-rw-r--r--spec/graphql/types/query_type_spec.rb7
-rw-r--r--spec/lib/gitlab/import_export/attribute_configuration_spec.rb5
-rw-r--r--spec/lib/gitlab/import_export/references_configuration_spec.rb5
-rw-r--r--spec/lib/gitlab/usage/metric_definition_spec.rb7
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb1
-rw-r--r--spec/requests/api/graphql/ci/runners_spec.rb114
7 files changed, 268 insertions, 7 deletions
diff --git a/spec/graphql/resolvers/ci/runners_resolver_spec.rb b/spec/graphql/resolvers/ci/runners_resolver_spec.rb
new file mode 100644
index 00000000000..006d6785506
--- /dev/null
+++ b/spec/graphql/resolvers/ci/runners_resolver_spec.rb
@@ -0,0 +1,136 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Resolvers::Ci::RunnersResolver do
+ include GraphqlHelpers
+
+ let_it_be(:user) { create_default(:user, :admin) }
+ let_it_be(:group) { create(:group, :public) }
+ let_it_be(:project) { create(:project, :repository, :public) }
+
+ let_it_be(:inactive_project_runner) do
+ create(:ci_runner, :project, projects: [project], active: false, contacted_at: 1.minute.ago, tag_list: %w(project_runner))
+ end
+
+ let_it_be(:offline_project_runner) do
+ create(:ci_runner, :project, projects: [project], contacted_at: 1.day.ago, tag_list: %w(project_runner active_runner))
+ end
+
+ let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group], contacted_at: 1.second.ago) }
+ let_it_be(:instance_runner) { create(:ci_runner, :instance, contacted_at: 2.minutes.ago, tag_list: %w(instance_runner active_runner)) }
+
+ describe '#resolve' do
+ subject { resolve(described_class, ctx: { current_user: user }, args: args).items.to_a }
+
+ let(:args) do
+ {}
+ end
+
+ context 'without sort' do
+ it 'returns all the runners' do
+ is_expected.to contain_exactly(inactive_project_runner, offline_project_runner, group_runner, instance_runner)
+ end
+ end
+
+ context 'with a sort argument' do
+ context "set to :contacted_asc" do
+ let(:args) do
+ { sort: :contacted_asc }
+ end
+
+ it { is_expected.to eq([offline_project_runner, instance_runner, inactive_project_runner, group_runner]) }
+ end
+
+ context "set to :created_date" do
+ let(:args) do
+ { sort: :created_date }
+ end
+
+ it { is_expected.to eq([instance_runner, group_runner, offline_project_runner, inactive_project_runner]) }
+ end
+ end
+
+ context 'when type is filtered' do
+ let(:args) do
+ { type: runner_type.to_s }
+ end
+
+ context 'to instance runners' do
+ let(:runner_type) { :instance_type }
+
+ it 'returns the instance runner' do
+ is_expected.to contain_exactly(instance_runner)
+ end
+ end
+
+ context 'to group runners' do
+ let(:runner_type) { :group_type }
+
+ it 'returns the group runner' do
+ is_expected.to contain_exactly(group_runner)
+ end
+ end
+
+ context 'to project runners' do
+ let(:runner_type) { :project_type }
+
+ it 'returns the project runner' do
+ is_expected.to contain_exactly(inactive_project_runner, offline_project_runner)
+ end
+ end
+ end
+
+ context 'when status is filtered' do
+ let(:args) do
+ { status: runner_status.to_s }
+ end
+
+ context 'to active runners' do
+ let(:runner_status) { :active }
+
+ it 'returns the instance and group runners' do
+ is_expected.to contain_exactly(offline_project_runner, group_runner, instance_runner)
+ end
+ end
+
+ context 'to offline runners' do
+ let(:runner_status) { :offline }
+
+ it 'returns the offline project runner' do
+ is_expected.to contain_exactly(offline_project_runner)
+ end
+ end
+ end
+
+ context 'when tag list is filtered' do
+ let(:args) do
+ { tag_list: tag_list }
+ end
+
+ context 'with "project_runner" tag' do
+ let(:tag_list) { ['project_runner'] }
+
+ it 'returns the project_runner runners' do
+ is_expected.to contain_exactly(offline_project_runner, inactive_project_runner)
+ end
+ end
+
+ context 'with "project_runner" and "active_runner" tags as comma-separated string' do
+ let(:tag_list) { ['project_runner,active_runner'] }
+
+ it 'returns the offline_project_runner runner' do
+ is_expected.to contain_exactly(offline_project_runner)
+ end
+ end
+
+ context 'with "active_runner" and "instance_runner" tags as array' do
+ let(:tag_list) { %w[instance_runner active_runner] }
+
+ it 'returns the offline_project_runner runner' do
+ is_expected.to contain_exactly(instance_runner)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb
index f0e80fa8f14..9a8f2090cc1 100644
--- a/spec/graphql/types/query_type_spec.rb
+++ b/spec/graphql/types/query_type_spec.rb
@@ -25,6 +25,7 @@ RSpec.describe GitlabSchema.types['Query'] do
usage_trends_measurements
runner_platforms
runner
+ runners
]
expect(described_class).to have_graphql_fields(*expected_fields).at_least
@@ -91,6 +92,12 @@ RSpec.describe GitlabSchema.types['Query'] do
it { is_expected.to have_graphql_type(Types::Ci::RunnerType) }
end
+ describe 'runners field' do
+ subject { described_class.fields['runners'] }
+
+ it { is_expected.to have_graphql_type(Types::Ci::RunnerType.connection_type) }
+ end
+
describe 'runner_platforms field' do
subject { described_class.fields['runnerPlatforms'] }
diff --git a/spec/lib/gitlab/import_export/attribute_configuration_spec.rb b/spec/lib/gitlab/import_export/attribute_configuration_spec.rb
index 0581f07dd3f..7e17d56def0 100644
--- a/spec/lib/gitlab/import_export/attribute_configuration_spec.rb
+++ b/spec/lib/gitlab/import_export/attribute_configuration_spec.rb
@@ -35,8 +35,9 @@ RSpec.describe 'Import/Export attribute configuration' do
<<-MSG
It looks like #{relation_class}, which is exported using the project Import/Export, has new attributes: #{new_attributes.join(',')}
- Please add the attribute(s) to SAFE_MODEL_ATTRIBUTES if you consider this can be exported.
- Please blacklist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its correspondent
+ Please add the attribute(s) to SAFE_MODEL_ATTRIBUTES if they can be exported.
+
+ Please denylist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its corresponding
model in the +excluded_attributes+ section.
SAFE_MODEL_ATTRIBUTES: #{File.expand_path(safe_attributes_file)}
diff --git a/spec/lib/gitlab/import_export/references_configuration_spec.rb b/spec/lib/gitlab/import_export/references_configuration_spec.rb
index 2934d0059ee..6320fbed975 100644
--- a/spec/lib/gitlab/import_export/references_configuration_spec.rb
+++ b/spec/lib/gitlab/import_export/references_configuration_spec.rb
@@ -38,8 +38,9 @@ RSpec.describe 'Import/Export Project configuration' do
<<-MSG
It looks like #{relation_class}, which is exported using the project Import/Export, has references: #{prohibited_keys.join(',')}
- Please replace it with actual relation in IMPORT_EXPORT_CONFIG if you consider this can be exported.
- Please blacklist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its correspondent
+ Please replace it with actual relation in IMPORT_EXPORT_CONFIG if they can be exported.
+
+ Please denylist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its corresponding
model in the +excluded_attributes+ section.
IMPORT_EXPORT_CONFIG: #{Gitlab::ImportExport.config_file}
diff --git a/spec/lib/gitlab/usage/metric_definition_spec.rb b/spec/lib/gitlab/usage/metric_definition_spec.rb
index 65cd4300ee6..92e51b8ea23 100644
--- a/spec/lib/gitlab/usage/metric_definition_spec.rb
+++ b/spec/lib/gitlab/usage/metric_definition_spec.rb
@@ -38,6 +38,11 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
File.write(path, content)
end
+ after do
+ # Reset memoized `definitions` result
+ described_class.instance_variable_set(:@definitions, nil)
+ end
+
it 'has all definitons valid' do
expect { described_class.definitions }.not_to raise_error(Gitlab::Usage::Metric::InvalidMetricError)
end
@@ -193,8 +198,6 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
File.join(metric2, '**', '*.yml')
]
)
- # Reset memoized `definitions` result
- described_class.instance_variable_set(:@definitions, nil)
end
after do
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index b11cc6d8f6e..d4b6ac09261 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -1332,7 +1332,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
'i_analytics_dev_ops_score' => 123,
'i_analytics_instance_statistics' => 123,
'p_analytics_merge_request' => 123,
- 'g_analytics_merge_request' => 123,
'i_analytics_dev_ops_adoption' => 123,
'users_viewing_analytics_group_devops_adoption' => 123,
'analytics_unique_visits_for_any_target' => 543,
diff --git a/spec/requests/api/graphql/ci/runners_spec.rb b/spec/requests/api/graphql/ci/runners_spec.rb
new file mode 100644
index 00000000000..778fe5b129e
--- /dev/null
+++ b/spec/requests/api/graphql/ci/runners_spec.rb
@@ -0,0 +1,114 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe 'Query.runners' do
+ include GraphqlHelpers
+
+ let_it_be(:current_user) { create_default(:user, :admin) }
+
+ describe 'Query.runners' do
+ let_it_be(:project) { create(:project, :repository, :public) }
+ let_it_be(:instance_runner) { create(:ci_runner, :instance, version: 'abc', revision: '123', description: 'Instance runner', ip_address: '127.0.0.1') }
+ let_it_be(:project_runner) { create(:ci_runner, :project, active: false, version: 'def', revision: '456', description: 'Project runner', projects: [project], ip_address: '127.0.0.1') }
+
+ let(:runners_graphql_data) { graphql_data['runners'] }
+
+ let(:params) { {} }
+
+ let(:fields) do
+ <<~QUERY
+ nodes {
+ #{all_graphql_fields_for('CiRunner')}
+ }
+ QUERY
+ end
+
+ let(:query) do
+ %(
+ query {
+ runners(type:#{runner_type},status:#{status}) {
+ #{fields}
+ }
+ }
+ )
+ end
+
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ shared_examples 'a working graphql query returning expected runner' do
+ it_behaves_like 'a working graphql query'
+
+ it 'returns expected runner' do
+ expect(runners_graphql_data['nodes'].map { |n| n['id'] }).to contain_exactly(expected_runner.to_global_id.to_s)
+ end
+ end
+
+ context 'runner_type is INSTANCE_TYPE and status is ACTIVE' do
+ let(:runner_type) { 'INSTANCE_TYPE' }
+ let(:status) { 'ACTIVE' }
+
+ let!(:expected_runner) { instance_runner }
+
+ it_behaves_like 'a working graphql query returning expected runner'
+ end
+
+ context 'runner_type is PROJECT_TYPE and status is NOT_CONNECTED' do
+ let(:runner_type) { 'PROJECT_TYPE' }
+ let(:status) { 'NOT_CONNECTED' }
+
+ let!(:expected_runner) { project_runner }
+
+ it_behaves_like 'a working graphql query returning expected runner'
+ end
+ end
+
+ describe 'pagination' do
+ let(:data_path) { [:runners] }
+
+ def pagination_query(params)
+ graphql_query_for(:runners, params, "#{page_info} nodes { id }")
+ end
+
+ def pagination_results_data(runners)
+ runners.map { |runner| GitlabSchema.parse_gid(runner['id'], expected_type: ::Ci::Runner).model_id.to_i }
+ end
+
+ let_it_be(:runners) do
+ common_args = {
+ version: 'abc',
+ revision: '123',
+ ip_address: '127.0.0.1'
+ }
+
+ [
+ create(:ci_runner, :instance, created_at: 4.days.ago, contacted_at: 3.days.ago, **common_args),
+ create(:ci_runner, :instance, created_at: 30.hours.ago, contacted_at: 1.day.ago, **common_args),
+ create(:ci_runner, :instance, created_at: 1.day.ago, contacted_at: 1.hour.ago, **common_args),
+ create(:ci_runner, :instance, created_at: 2.days.ago, contacted_at: 2.days.ago, **common_args),
+ create(:ci_runner, :instance, created_at: 3.days.ago, contacted_at: 1.second.ago, **common_args)
+ ]
+ end
+
+ context 'when sorted by contacted_at ascending' do
+ let(:ordered_runners) { runners.sort_by(&:contacted_at) }
+
+ it_behaves_like 'sorted paginated query' do
+ let(:sort_param) { :CONTACTED_ASC }
+ let(:first_param) { 2 }
+ let(:expected_results) { ordered_runners.map(&:id) }
+ end
+ end
+
+ context 'when sorted by created_at' do
+ let(:ordered_runners) { runners.sort_by(&:created_at).reverse }
+
+ it_behaves_like 'sorted paginated query' do
+ let(:sort_param) { :CREATED_DESC }
+ let(:first_param) { 2 }
+ let(:expected_results) { ordered_runners.map(&:id) }
+ end
+ end
+ end
+end