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/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-06-09 15:11:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-09 15:11:14 +0300
commit3fd585614449ccab7fdab083f210c09eb16a6ed2 (patch)
tree225d8bdfcd0bfd5efe0da44348dd97be558be288 /spec/lib
parent8b50d36626f3a71a2d8552a316d700510559b0de (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb22
-rw-r--r--spec/lib/gitlab/error_tracking/error_repository/open_api_strategy_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/import_test_coverage_spec.rb45
-rw-r--r--spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb24
-rw-r--r--spec/lib/gitlab/utils/usage_data_spec.rb2
5 files changed, 43 insertions, 52 deletions
diff --git a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
index baabab73ea2..ac66fc3b773 100644
--- a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
+++ b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
+RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace, feature_category: :continuous_delivery do
describe '#unmet?' do
let(:build) { create(:ci_build) }
@@ -17,15 +17,13 @@ RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
end
context 'build has a deployment' do
- let!(:deployment) { create(:deployment, deployable: build, cluster: cluster) }
-
context 'and a cluster to deploy to' do
- let(:cluster) { create(:cluster, :group) }
+ let!(:deployment) { create(:deployment, :on_cluster, deployable: build) }
it { is_expected.to be_truthy }
context 'and the cluster is not managed' do
- let(:cluster) { create(:cluster, :not_managed, projects: [build.project]) }
+ let!(:deployment) { create(:deployment, :on_cluster_not_managed, deployable: build) }
it { is_expected.to be_falsey }
end
@@ -63,8 +61,8 @@ RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
subject { prerequisite.complete! }
context 'completion is required' do
- let(:cluster) { create(:cluster, :group) }
- let(:deployment) { create(:deployment, cluster: cluster) }
+ let(:cluster) { deployment.cluster }
+ let(:deployment) { create(:deployment, :on_cluster) }
let(:service) { double(execute: true) }
let(:kubernetes_namespace) { double }
@@ -84,12 +82,12 @@ RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
it 'creates a namespace using a new record' do
expect(Clusters::BuildKubernetesNamespaceService)
.to receive(:new)
- .with(cluster, environment: deployment.environment)
+ .with(deployment.cluster, environment: deployment.environment)
.and_return(namespace_builder)
expect(Clusters::Kubernetes::CreateOrUpdateNamespaceService)
.to receive(:new)
- .with(cluster: cluster, kubernetes_namespace: kubernetes_namespace)
+ .with(cluster: deployment.cluster, kubernetes_namespace: kubernetes_namespace)
.and_return(service)
expect(service).to receive(:execute).once
@@ -112,12 +110,12 @@ RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
it 'creates a namespace' do
expect(Clusters::BuildKubernetesNamespaceService)
.to receive(:new)
- .with(cluster, environment: deployment.environment)
+ .with(deployment.cluster, environment: deployment.environment)
.and_return(namespace_builder)
expect(Clusters::Kubernetes::CreateOrUpdateNamespaceService)
.to receive(:new)
- .with(cluster: cluster, kubernetes_namespace: kubernetes_namespace)
+ .with(cluster: deployment.cluster, kubernetes_namespace: kubernetes_namespace)
.and_return(service)
expect(service).to receive(:execute).once
@@ -150,7 +148,7 @@ RSpec.describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
expect(Clusters::Kubernetes::CreateOrUpdateNamespaceService)
.to receive(:new)
- .with(cluster: cluster, kubernetes_namespace: kubernetes_namespace)
+ .with(cluster: deployment.cluster, kubernetes_namespace: kubernetes_namespace)
.and_return(service)
subject
diff --git a/spec/lib/gitlab/error_tracking/error_repository/open_api_strategy_spec.rb b/spec/lib/gitlab/error_tracking/error_repository/open_api_strategy_spec.rb
index 394c45121dc..3a5df997f7c 100644
--- a/spec/lib/gitlab/error_tracking/error_repository/open_api_strategy_spec.rb
+++ b/spec/lib/gitlab/error_tracking/error_repository/open_api_strategy_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe Gitlab::ErrorTracking::ErrorRepository::OpenApiStrategy do
before do
# Disabled in spec_helper by default thus we need to enable it here.
- stub_feature_flags(use_click_house_database_for_error_tracking: true)
+ stub_feature_flags(gitlab_error_tracking: true)
end
shared_examples 'exception logging' do
diff --git a/spec/lib/gitlab/import_export/import_test_coverage_spec.rb b/spec/lib/gitlab/import_export/import_test_coverage_spec.rb
index d8a4230e5da..1d3fc764b50 100644
--- a/spec/lib/gitlab/import_export/import_test_coverage_spec.rb
+++ b/spec/lib/gitlab/import_export/import_test_coverage_spec.rb
@@ -7,7 +7,7 @@ require 'spec_helper'
# Fixture JSONs we use for testing Import such as
# `spec/fixtures/lib/gitlab/import_export/complex/project.json`
# should include these relations being non-empty.
-RSpec.describe 'Test coverage of the Project Import' do
+RSpec.describe 'Test coverage of the Project Import', feature_category: :importers do
include ConfigurationHelper
# `muted_relations` is a technical debt.
@@ -18,7 +18,6 @@ RSpec.describe 'Test coverage of the Project Import' do
let(:muted_relations) do
%w[
project.milestones.events.push_event_payload
- project.issues.events
project.issues.events.push_event_payload
project.issues.notes.events
project.issues.notes.events.push_event_payload
@@ -53,19 +52,23 @@ RSpec.describe 'Test coverage of the Project Import' do
project.boards.lists.label.priorities
project.service_desk_setting
project.security_setting
+ project.push_rule
+ project.approval_rules
+ project.approval_rules.approval_project_rules_protected_branches
+ project.approval_rules.approval_project_rules_users
].freeze
end
- # A list of JSON fixture files we use to test Import.
- # Most of the relations are present in `complex/project.json`
+ # A list of project tree fixture files we use to test Import.
+ # Most of the relations are present in `complex/tree`
# which is our main fixture.
- let(:project_json_fixtures) do
+ let(:project_tree_fixtures) do
[
- 'spec/fixtures/lib/gitlab/import_export/complex/project.json',
- 'spec/fixtures/lib/gitlab/import_export/group/project.json',
- 'spec/fixtures/lib/gitlab/import_export/light/project.json',
- 'spec/fixtures/lib/gitlab/import_export/milestone-iid/project.json',
- 'spec/fixtures/lib/gitlab/import_export/designs/project.json'
+ 'spec/fixtures/lib/gitlab/import_export/complex/tree',
+ 'spec/fixtures/lib/gitlab/import_export/group/tree',
+ 'spec/fixtures/lib/gitlab/import_export/light/tree',
+ 'spec/fixtures/lib/gitlab/import_export/milestone-iid/tree',
+ 'spec/fixtures/lib/gitlab/import_export/designs/tree'
].freeze
end
@@ -82,16 +85,30 @@ RSpec.describe 'Test coverage of the Project Import' do
end
def tested_relations
- project_json_fixtures.flat_map(&method(:relations_from_json)).to_set
+ project_tree_fixtures.flat_map(&method(:relations_from_tree)).to_set
end
- def relations_from_json(json_file)
- json = Gitlab::Json.parse(File.read(json_file))
+ def relations_from_tree(json_tree_path)
+ json = convert_tree_to_json(json_tree_path)
[].tap { |res| gather_relations({ project: json }, res, []) }
.map { |relation_names| relation_names.join('.') }
end
+ def convert_tree_to_json(json_tree_path)
+ json = Gitlab::Json.parse(File.read(File.join(json_tree_path, 'project.json')))
+
+ Dir["#{json_tree_path}/project/*.ndjson"].each do |ndjson|
+ relation_name = File.basename(ndjson, '.ndjson')
+ json[relation_name] = []
+ File.foreach(ndjson) do |line|
+ json[relation_name] << Gitlab::Json.parse(line)
+ end
+ end
+
+ json
+ end
+
def gather_relations(item, res, path)
case item
when Hash
@@ -112,7 +129,7 @@ RSpec.describe 'Test coverage of the Project Import' do
These relations seem to be added recently and
they expected to be covered in our Import specs: #{not_tested_relations}.
- To do that, expand one of the files listed in `project_json_fixtures`
+ To do that, expand one of the files listed in `project_tree_fixtures`
(or expand the list if you consider adding a new fixture file).
After that, add a new spec into
diff --git a/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb b/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb
deleted file mode 100644
index c2c50751c3f..00000000000
--- a/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::ImportExport::LegacyRelationTreeSaver do
- let(:exportable) { create(:group) }
- let(:relation_tree_saver) { described_class.new }
- let(:tree) { {} }
-
- describe '#serialize' do
- let(:serializer) { instance_double(Gitlab::ImportExport::FastHashSerializer) }
-
- it 'uses FastHashSerializer' do
- expect(Gitlab::ImportExport::FastHashSerializer)
- .to receive(:new)
- .with(exportable, tree)
- .and_return(serializer)
-
- expect(serializer).to receive(:execute)
-
- relation_tree_saver.serialize(exportable, tree)
- end
- end
-end
diff --git a/spec/lib/gitlab/utils/usage_data_spec.rb b/spec/lib/gitlab/utils/usage_data_spec.rb
index 586ee04a835..b4672a9d1c4 100644
--- a/spec/lib/gitlab/utils/usage_data_spec.rb
+++ b/spec/lib/gitlab/utils/usage_data_spec.rb
@@ -182,7 +182,7 @@ RSpec.describe Gitlab::Utils::UsageData do
end
it 'counts over joined relations' do
- expect(described_class.estimate_batch_distinct_count(model.joins(:build), "ci_builds.name")).to eq(ci_builds_estimated_cardinality)
+ expect(described_class.estimate_batch_distinct_count(model.joins(:build), "#{Ci::Build.table_name}.name")).to eq(ci_builds_estimated_cardinality)
end
it 'counts with :column field with batch_size of 50K' do