diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-27 14:45:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-27 14:45:16 +0300 |
commit | f444f745544528accf5811bb9a8fb0a252775d3b (patch) | |
tree | c248e283ea2825b68f405e738faea0e56ed57bba /spec | |
parent | 58fa510acd34ab3c8b36be95f5e7b58dd9b0f5f4 (diff) |
Add latest changes from gitlab-org/gitlab@12-6-stable-ee
Diffstat (limited to 'spec')
7 files changed, 115 insertions, 18 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index b4549e4e635..902a84a843b 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::PipelinesController do include ApiHelpers let_it_be(:user) { create(:user) } - let(:project) { create(:project, :public, :repository) } + let_it_be(:project) { create(:project, :public, :repository) } let(:feature) { ProjectFeature::ENABLED } before do @@ -19,12 +19,12 @@ describe Projects::PipelinesController do describe 'GET index.json' do before do - %w(pending running success failed canceled).each_with_index do |status, index| - create_pipeline(status, project.commit("HEAD~#{index}")) - end + create_all_pipeline_types end context 'when using persisted stages', :request_store do + render_views + before do stub_feature_flags(ci_pipeline_persisted_stages: true) end @@ -32,9 +32,7 @@ describe Projects::PipelinesController do it 'returns serialized pipelines', :request_store do expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original - queries = ActiveRecord::QueryRecorder.new do - get_pipelines_index_json - end + get_pipelines_index_json expect(response).to have_gitlab_http_status(:ok) expect(response).to match_response_schema('pipeline') @@ -49,8 +47,22 @@ describe Projects::PipelinesController do json_response.dig('pipelines', 0, 'details', 'stages').tap do |stages| expect(stages.count).to eq 3 end + end + + it 'does not execute N+1 queries' do + get_pipelines_index_json + + control_count = ActiveRecord::QueryRecorder.new do + get_pipelines_index_json + end.count - expect(queries.count).to be + create_all_pipeline_types + + # There appears to be one extra query for Pipelines#has_warnings? for some reason + expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['pipelines'].count).to eq 10 end end @@ -133,19 +145,27 @@ describe Projects::PipelinesController do format: :json end + def create_all_pipeline_types + %w(pending running success failed canceled).each_with_index do |status, index| + create_pipeline(status, project.commit("HEAD~#{index}")) + end + end + def create_pipeline(status, sha) + user = create(:user) pipeline = create(:ci_empty_pipeline, status: status, project: project, - sha: sha) + sha: sha, + user: user) - create_build(pipeline, 'build', 1, 'build') - create_build(pipeline, 'test', 2, 'test') - create_build(pipeline, 'deploy', 3, 'deploy') + create_build(pipeline, 'build', 1, 'build', user) + create_build(pipeline, 'test', 2, 'test', user) + create_build(pipeline, 'deploy', 3, 'deploy', user) end - def create_build(pipeline, stage, stage_idx, name) + def create_build(pipeline, stage, stage_idx, name, user = nil) status = %w[created running pending success failed canceled].sample - create(:ci_build, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name, status: status) + create(:ci_build, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name, status: status, user: user) end end diff --git a/spec/factories/error_tracking/error_event.rb b/spec/factories/error_tracking/error_event.rb index c4dcd67bc9f..1590095f1bd 100644 --- a/spec/factories/error_tracking/error_event.rb +++ b/spec/factories/error_tracking/error_event.rb @@ -36,6 +36,16 @@ FactoryBot.define do ] }, { + 'function' => 'print', + 'lineNo' => 3, + 'filename' => 'hello_world.php', + 'context' => [ + [1, "// PHP/Hack example\n"], + [2, "<?php\n"], + [3, "echo 'Hello, World!';\n"] + ] + }, + { 'filename' => 'blank.txt' } ] diff --git a/spec/finders/clusters/knative_serving_namespace_finder_spec.rb b/spec/finders/clusters/knative_serving_namespace_finder_spec.rb new file mode 100644 index 00000000000..f3587df680a --- /dev/null +++ b/spec/finders/clusters/knative_serving_namespace_finder_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Clusters::KnativeServingNamespaceFinder do + include KubernetesHelpers + let(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:service) { environment.deployment_platform } + let(:project) { cluster.cluster_project.project } + let(:environment) { create(:environment, project: project) } + + subject { described_class.new(cluster) } + + before do + stub_kubeclient_discover(service.api_url) + end + + it 'finds the namespace in a cluster where it exists' do + stub_kubeclient_get_namespace(service.api_url, namespace: Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE) + expect(subject.execute).to be_a Kubeclient::Resource + end + + it 'returns nil in a cluster where it does not' do + stub_kubeclient_get_namespace( + service.api_url, + namespace: Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE, + response: { + status: [404, "Resource Not Found"] + } + ) + expect(subject.execute).to be nil + end + + it 'returns nil in a cluster where the lookup results in a 403 as it will in some versions of kubernetes' do + stub_kubeclient_get_namespace( + service.api_url, + namespace: Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE, + response: { + status: [403, "Resource Not Found"] + } + ) + expect(subject.execute).to be nil + end + + it 'raises an error if error code is not 404 or 403' do + stub_kubeclient_get_namespace( + service.api_url, + namespace: Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE, + response: { + status: [500, "Internal Server Error"] + } + ) + expect { subject.execute }.to raise_error(Kubeclient::HttpError) + end +end diff --git a/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb b/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb index 04ef5ba516e..d553fb4848b 100644 --- a/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb +++ b/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb @@ -49,6 +49,16 @@ describe Gitlab::ErrorTracking::StackTraceHighlightDecorator do ] }, { + 'function' => 'print', + 'lineNo' => 3, + 'filename' => 'hello_world.php', + 'context' => [ + [1, '<span id="LC1" class="line" lang="hack"><span class="c1">// PHP/Hack example</span></span>'], + [2, '<span id="LC1" class="line" lang="hack"><span class="cp"><?php</span></span>'], + [3, '<span id="LC1" class="line" lang="hack"><span class="k">echo</span> <span class="s1">\'Hello, World!\'</span><span class="p">;</span></span>'] + ] + }, + { 'filename' => 'blank.txt' } ] diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 2ea563c50b6..817aedc19b0 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -160,6 +160,7 @@ ci_pipelines: - user - stages - statuses +- latest_statuses_ordered_by_stage - builds - processables - trigger_requests @@ -168,6 +169,7 @@ ci_pipelines: - auto_canceled_pipelines - auto_canceled_jobs - pending_builds +- failed_builds - retryable_builds - cancelable_statuses - manual_actions diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index f1f761a6fd0..8158277ffbc 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -159,7 +159,7 @@ describe PipelineSerializer do it 'verifies number of queries', :request_store do recorded = ActiveRecord::QueryRecorder.new { subject } - expected_queries = Gitlab.ee? ? 38 : 35 + expected_queries = Gitlab.ee? ? 42 : 39 expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0) @@ -180,7 +180,7 @@ describe PipelineSerializer do # pipeline. With the same ref this check is cached but if refs are # different then there is an extra query per ref # https://gitlab.com/gitlab-org/gitlab-foss/issues/46368 - expected_queries = Gitlab.ee? ? 41 : 38 + expected_queries = Gitlab.ee? ? 45 : 42 expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0) diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index ad4ae93a027..b2145ca729f 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -229,9 +229,9 @@ module KubernetesHelpers .to_return(kube_response(kube_v1_namespace_list_body)) end - def stub_kubeclient_get_namespace(api_url, namespace: 'default') + def stub_kubeclient_get_namespace(api_url, namespace: 'default', response: kube_response({})) WebMock.stub_request(:get, api_url + "/api/v1/namespaces/#{namespace}") - .to_return(kube_response({})) + .to_return(response) end def stub_kubeclient_put_cluster_role(api_url, name) |