diff options
Diffstat (limited to 'spec/support')
5 files changed, 146 insertions, 14 deletions
diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index 89360b55de2..77acad31d62 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -27,7 +27,10 @@ module KubernetesHelpers WebMock.stub_request(:get, api_url + '/api/v1').to_return(kube_response(kube_v1_discovery_body)) WebMock .stub_request(:get, api_url + '/apis/extensions/v1beta1') - .to_return(kube_response(kube_v1beta1_discovery_body)) + .to_return(kube_response(kube_extensions_v1beta1_discovery_body)) + WebMock + .stub_request(:get, api_url + '/apis/apps/v1') + .to_return(kube_response(kube_apps_v1_discovery_body)) WebMock .stub_request(:get, api_url + '/apis/rbac.authorization.k8s.io/v1') .to_return(kube_response(kube_v1_rbac_authorization_discovery_body)) @@ -275,15 +278,33 @@ module KubernetesHelpers } end - def kube_v1beta1_discovery_body + # From Kubernetes 1.16+ Deployments are no longer served from apis/extensions + def kube_1_16_extensions_v1beta1_discovery_body + { + "kind" => "APIResourceList", + "resources" => [ + { "name" => "ingresses", "namespaced" => true, "kind" => "Deployment" } + ] + } + end + + def kube_extensions_v1beta1_discovery_body { "kind" => "APIResourceList", "resources" => [ - { "name" => "pods", "namespaced" => true, "kind" => "Pod" }, { "name" => "deployments", "namespaced" => true, "kind" => "Deployment" }, - { "name" => "secrets", "namespaced" => true, "kind" => "Secret" }, - { "name" => "serviceaccounts", "namespaced" => true, "kind" => "ServiceAccount" }, - { "name" => "services", "namespaced" => true, "kind" => "Service" } + { "name" => "ingresses", "namespaced" => true, "kind" => "Ingress" } + ] + } + end + + # Yes, deployments are defined in both apis/extensions/v1beta1 and apis/v1 + # (for Kubernetes < 1.16). This matches what Kubenetes API server returns. + def kube_apps_v1_discovery_body + { + "kind" => "APIResourceList", + "resources" => [ + { "name" => "deployments", "namespaced" => true, "kind" => "Deployment" } ] } end diff --git a/spec/support/shared_contexts/features/error_tracking_shared_context.rb b/spec/support/shared_contexts/features/error_tracking_shared_context.rb new file mode 100644 index 00000000000..3da6e2b13bb --- /dev/null +++ b/spec/support/shared_contexts/features/error_tracking_shared_context.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +shared_context 'sentry error tracking context feature' do + include ReactiveCachingHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:project_error_tracking_settings) { create(:project_error_tracking_setting, project: project) } + let_it_be(:issue_response_body) { fixture_file('sentry/issue_sample_response.json') } + let_it_be(:issue_response) { JSON.parse(issue_response_body) } + let_it_be(:event_response_body) { fixture_file('sentry/issue_latest_event_sample_response.json') } + let_it_be(:event_response) { JSON.parse(event_response_body) } + let(:sentry_api_urls) { Sentry::ApiUrls.new(project_error_tracking_settings.api_url) } + let(:issue_id) { issue_response['id'] } + + before do + request_headers = { 'Authorization' => 'Bearer access_token_123', 'Content-Type' => 'application/json' } + response_headers = { 'Content-Type' => 'application/json' } + issue_url = sentry_api_urls.issue_url(issue_id).to_s + stub_request(:get, issue_url) + .with(headers: request_headers) + .to_return(status: 200, body: issue_response_body, headers: response_headers) + event_url = sentry_api_urls.issue_latest_event_url(issue_id).to_s + stub_request(:get, event_url) + .with(headers: request_headers) + .to_return(status: 200, body: event_response_body, headers: response_headers) + end +end diff --git a/spec/support/shared_contexts/policies/project_policy_shared_context.rb b/spec/support/shared_contexts/policies/project_policy_shared_context.rb index 480c5a0fda0..29a64e9b559 100644 --- a/spec/support/shared_contexts/policies/project_policy_shared_context.rb +++ b/spec/support/shared_contexts/policies/project_policy_shared_context.rb @@ -13,7 +13,7 @@ RSpec.shared_context 'ProjectPolicy context' do %i[ read_project read_board read_list read_wiki read_issue read_project_for_iids read_issue_iid read_label - read_milestone read_project_snippet read_project_member read_note + read_milestone read_snippet read_project_member read_note create_project create_issue create_note upload_file create_merge_request_in award_emoji ] @@ -21,7 +21,7 @@ RSpec.shared_context 'ProjectPolicy context' do let(:base_reporter_permissions) do %i[ - download_code fork_project create_project_snippet update_issue + download_code fork_project create_snippet update_issue admin_issue admin_label admin_list read_commit_status read_build read_container_image read_pipeline read_environment read_deployment read_merge_request download_wiki_code read_sentry_issue read_prometheus @@ -45,8 +45,8 @@ RSpec.shared_context 'ProjectPolicy context' do let(:base_maintainer_permissions) do %i[ - push_to_delete_protected_branch update_project_snippet - admin_project_snippet admin_project_member admin_note admin_wiki admin_project + push_to_delete_protected_branch update_snippet + admin_snippet admin_project_member admin_note admin_wiki admin_project admin_commit_status admin_build admin_container_image admin_pipeline admin_environment admin_deployment destroy_release add_cluster daily_statistics diff --git a/spec/support/shared_examples/features/error_tracking_shared_example.rb b/spec/support/shared_examples/features/error_tracking_shared_example.rb new file mode 100644 index 00000000000..f53adece864 --- /dev/null +++ b/spec/support/shared_examples/features/error_tracking_shared_example.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +shared_examples 'error tracking index page' do + it 'renders the error index page' do + within('div.js-title-container') do + expect(page).to have_content(project.namespace.name) + expect(page).to have_content(project.name) + end + + within('div.error-list') do + expect(page).to have_content('Error') + expect(page).to have_content('Events') + expect(page).to have_content('Users') + expect(page).to have_content('Last Seen') + end + end + + it 'loads the error show page on click' do + click_on issues_response[0]['title'] + + wait_for_requests + + expect(page).to have_content('Error Details') + end + + it 'renders the error index data' do + Timecop.freeze(2020, 01, 01, 12, 0, 0) do + within('div.error-list') do + expect(page).to have_content(issues_response[0]['title']) + expect(page).to have_content(issues_response[0]['count'].to_s) + expect(page).to have_content(issues_response[0]['last_seen']) + expect(page).to have_content('1 year ago') + end + end + end +end + +shared_examples 'expanded stack trace context' do |selected_line: nil, expected_line: 1| + it 'expands the stack trace context' do + within('div.stacktrace') do + find("div.file-holder:nth-child(#{selected_line}) svg.ic-chevron-right").click if selected_line + + expanded_line = find("div.file-holder:nth-child(#{expected_line})") + expect(expanded_line).to have_css('svg.ic-chevron-down') + + event_response['entries'][0]['data']['values'][0]['stacktrace']['frames'][-expected_line]['context'].each do |context| + expect(page).to have_content(context[0]) + end + end + end +end + +shared_examples 'error tracking show page' do + it 'renders the error details' do + release_short_version = issue_response['firstRelease']['shortVersion'] + + Timecop.freeze(2020, 01, 01, 12, 0, 0) do + expect(page).to have_content('1 month ago by raven.scripts.runner in main') + expect(page).to have_content(issue_response['metadata']['title']) + expect(page).to have_content('level: error') + expect(page).to have_content('Error Details') + expect(page).to have_content('GitLab Issue: https://gitlab.com/gitlab-org/gitlab/issues/1') + expect(page).to have_content("Sentry event: https://sentrytest.gitlab.com/sentry-org/sentry-project/issues/#{issue_id}") + expect(page).to have_content("First seen: 1 year ago (2018-11-06 9:19:55PM UTC) Release: #{release_short_version}") + expect(page).to have_content('Events: 1') + expect(page).to have_content('Users: 0') + end + end + + it 'renders the stack trace heading' do + expect(page).to have_content('Stack trace') + end + + it 'renders the stack trace' do + event_response['entries'][0]['data']['values'][0]['stacktrace']['frames'].each do |frame| + expect(frame['filename']).not_to be_nil + expect(page).to have_content(frame['filename']) + end + end + + # The first line is expanded by default if no line is selected + it_behaves_like 'expanded stack trace context', selected_line: nil, expected_line: 1 + it_behaves_like 'expanded stack trace context', selected_line: 8, expected_line: 8 +end diff --git a/spec/support/shared_examples/finders/snippet_visibility_shared_examples.rb b/spec/support/shared_examples/finders/snippet_visibility_shared_examples.rb index e2089ee623a..98ab141ab26 100644 --- a/spec/support/shared_examples/finders/snippet_visibility_shared_examples.rb +++ b/spec/support/shared_examples/finders/snippet_visibility_shared_examples.rb @@ -234,8 +234,8 @@ RSpec.shared_examples 'snippet visibility' do end context "For #{params[:project_type]} project and #{params[:user_type]} users" do - it 'agrees with the read_project_snippet policy' do - expect(can?(user, :read_project_snippet, snippet)).to eq(outcome) + it 'agrees with the read_snippet policy' do + expect(can?(user, :read_snippet, snippet)).to eq(outcome) end it 'returns proper outcome' do @@ -297,8 +297,8 @@ RSpec.shared_examples 'snippet visibility' do let!(:snippet) { create(:personal_snippet, visibility_level: snippet_visibility, author: author) } context "For personal and #{params[:snippet_visibility]} snippets with #{params[:user_type]} user" do - it 'agrees with read_personal_snippet policy' do - expect(can?(user, :read_personal_snippet, snippet)).to eq(outcome) + it 'agrees with read_snippet policy' do + expect(can?(user, :read_snippet, snippet)).to eq(outcome) end it 'returns proper outcome' do |