diff options
Diffstat (limited to 'spec/support/helpers')
-rw-r--r-- | spec/support/helpers/api_internal_base_helpers.rb | 85 | ||||
-rw-r--r-- | spec/support/helpers/features/canonical_link_helpers.rb | 28 | ||||
-rw-r--r-- | spec/support/helpers/git_http_helpers.rb | 26 | ||||
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 3 | ||||
-rw-r--r-- | spec/support/helpers/kubernetes_helpers.rb | 10 | ||||
-rw-r--r-- | spec/support/helpers/search_helpers.rb | 10 | ||||
-rw-r--r-- | spec/support/helpers/stub_experiments.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/stub_feature_flags.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/stub_object_storage.rb | 18 | ||||
-rw-r--r-- | spec/support/helpers/usage_data_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/wait_for_requests.rb | 11 | ||||
-rw-r--r-- | spec/support/helpers/wiki_helpers.rb | 10 |
12 files changed, 175 insertions, 38 deletions
diff --git a/spec/support/helpers/api_internal_base_helpers.rb b/spec/support/helpers/api_internal_base_helpers.rb new file mode 100644 index 00000000000..058d07c7a1d --- /dev/null +++ b/spec/support/helpers/api_internal_base_helpers.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +module APIInternalBaseHelpers + def gl_repository_for(container) + case container + when ProjectWiki + Gitlab::GlRepository::WIKI.identifier_for_container(container.project) + when Project + Gitlab::GlRepository::PROJECT.identifier_for_container(container) + when Snippet + Gitlab::GlRepository::SNIPPET.identifier_for_container(container) + else + nil + end + end + + def full_path_for(container) + case container + when PersonalSnippet + "snippets/#{container.id}" + when ProjectSnippet + "#{container.project.full_path}/snippets/#{container.id}" + else + container.full_path + end + end + + def pull(key, container, protocol = 'ssh') + post( + api("/internal/allowed"), + params: { + key_id: key.id, + project: full_path_for(container), + gl_repository: gl_repository_for(container), + action: 'git-upload-pack', + secret_token: secret_token, + protocol: protocol + } + ) + end + + def push(key, container, protocol = 'ssh', env: nil, changes: nil) + push_with_path(key, + full_path: full_path_for(container), + gl_repository: gl_repository_for(container), + protocol: protocol, + env: env, + changes: changes) + end + + def push_with_path(key, full_path:, gl_repository: nil, protocol: 'ssh', env: nil, changes: nil) + changes ||= 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master' + + params = { + changes: changes, + key_id: key.id, + project: full_path, + action: 'git-receive-pack', + secret_token: secret_token, + protocol: protocol, + env: env + } + params[:gl_repository] = gl_repository if gl_repository + + post( + api("/internal/allowed"), + params: params + ) + end + + def archive(key, container) + post( + api("/internal/allowed"), + params: { + ref: 'master', + key_id: key.id, + project: full_path_for(container), + gl_repository: gl_repository_for(container), + action: 'git-upload-archive', + secret_token: secret_token, + protocol: 'ssh' + } + ) + end +end diff --git a/spec/support/helpers/features/canonical_link_helpers.rb b/spec/support/helpers/features/canonical_link_helpers.rb new file mode 100644 index 00000000000..da3a28f1cb2 --- /dev/null +++ b/spec/support/helpers/features/canonical_link_helpers.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# These helpers allow you to manipulate with notes. +# +# Usage: +# describe "..." do +# include Spec::Support::Helpers::Features::CanonicalLinkHelpers +# ... +# +# expect(page).to have_canonical_link(url) +# +module Spec + module Support + module Helpers + module Features + module CanonicalLinkHelpers + def have_canonical_link(url) + have_xpath("//link[@rel=\"canonical\" and @href=\"#{url}\"]", visible: false) + end + + def have_any_canonical_links + have_xpath('//link[@rel="canonical"]', visible: false) + end + end + end + end + end +end diff --git a/spec/support/helpers/git_http_helpers.rb b/spec/support/helpers/git_http_helpers.rb index de8bb9ac8e3..c9c1c4dcfc9 100644 --- a/spec/support/helpers/git_http_helpers.rb +++ b/spec/support/helpers/git_http_helpers.rb @@ -5,45 +5,45 @@ require_relative 'workhorse_helpers' module GitHttpHelpers include WorkhorseHelpers - def clone_get(project, options = {}) + def clone_get(project, **options) get "/#{project}/info/refs", params: { service: 'git-upload-pack' }, headers: auth_env(*options.values_at(:user, :password, :spnego_request_token)) end - def clone_post(project, options = {}) + def clone_post(project, **options) post "/#{project}/git-upload-pack", headers: auth_env(*options.values_at(:user, :password, :spnego_request_token)) end - def push_get(project, options = {}) + def push_get(project, **options) get "/#{project}/info/refs", params: { service: 'git-receive-pack' }, headers: auth_env(*options.values_at(:user, :password, :spnego_request_token)) end - def push_post(project, options = {}) + def push_post(project, **options) post "/#{project}/git-receive-pack", headers: auth_env(*options.values_at(:user, :password, :spnego_request_token)) end def download(project, user: nil, password: nil, spnego_request_token: nil) - args = [project, { user: user, password: password, spnego_request_token: spnego_request_token }] + args = { user: user, password: password, spnego_request_token: spnego_request_token } - clone_get(*args) + clone_get(project, **args) yield response - clone_post(*args) + clone_post(project, **args) yield response end def upload(project, user: nil, password: nil, spnego_request_token: nil) - args = [project, { user: user, password: password, spnego_request_token: spnego_request_token }] + args = { user: user, password: password, spnego_request_token: spnego_request_token } - push_get(*args) + push_get(project, **args) yield response - push_post(*args) + push_post(project, **args) yield response end - def download_or_upload(*args, &block) - download(*args, &block) - upload(*args, &block) + def download_or_upload(project, **args, &block) + download(project, **args, &block) + upload(project, **args, &block) end def auth_env(user, password, spnego_request_token) diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 5635ba3df05..e754a24417c 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -234,7 +234,8 @@ module GraphqlHelpers end def post_graphql(query, current_user: nil, variables: nil, headers: {}) - post api('/', current_user, version: 'graphql'), params: { query: query, variables: variables }, headers: headers + params = { query: query, variables: variables&.to_json } + post api('/', current_user, version: 'graphql'), params: params, headers: headers end def post_graphql_mutation(mutation, current_user: nil) diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index 8882f31e2f4..16d2e84cc0f 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -153,7 +153,7 @@ module KubernetesHelpers options[:name] ||= "kubetest" options[:domain] ||= "example.com" - options[:response] ||= kube_response(kube_knative_services_body(options)) + options[:response] ||= kube_response(kube_knative_services_body(**options)) stub_kubeclient_discover(service.api_url) @@ -167,7 +167,7 @@ module KubernetesHelpers options[:namespace] ||= "default" WebMock.stub_request(:get, api_url + "/api/v1/namespaces/#{options[:namespace]}/secrets/#{options[:metadata_name]}") - .to_return(kube_response(kube_v1_secret_body(options))) + .to_return(kube_response(kube_v1_secret_body(**options))) end def stub_kubeclient_get_secret_error(api_url, name, namespace: 'default', status: 404) @@ -517,7 +517,7 @@ module KubernetesHelpers def kube_knative_services_body(**options) { "kind" => "List", - "items" => [knative_09_service(options)] + "items" => [knative_09_service(**options)] } end @@ -604,7 +604,7 @@ module KubernetesHelpers } end - def kube_deployment(name: "kube-deployment", environment_slug: "production", project_slug: "project-path-slug", track: nil) + def kube_deployment(name: "kube-deployment", environment_slug: "production", project_slug: "project-path-slug", track: nil, replicas: 3) { "metadata" => { "name" => name, @@ -617,7 +617,7 @@ module KubernetesHelpers "track" => track }.compact }, - "spec" => { "replicas" => 3 }, + "spec" => { "replicas" => replicas }, "status" => { "observedGeneration" => 4 } diff --git a/spec/support/helpers/search_helpers.rb b/spec/support/helpers/search_helpers.rb index db6e47459e9..328f272724a 100644 --- a/spec/support/helpers/search_helpers.rb +++ b/spec/support/helpers/search_helpers.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true module SearchHelpers + def fill_in_search(text) + page.within('.search-input-wrap') do + fill_in('search', with: text) + end + + wait_for_all_requests + end + def submit_search(query, scope: nil) page.within('.search-form, .search-page-form') do field = find_field('search') @@ -11,6 +19,8 @@ module SearchHelpers else click_button('Search') end + + wait_for_all_requests end end diff --git a/spec/support/helpers/stub_experiments.rb b/spec/support/helpers/stub_experiments.rb index ff3b02dc3f6..7a6154d5ef9 100644 --- a/spec/support/helpers/stub_experiments.rb +++ b/spec/support/helpers/stub_experiments.rb @@ -22,10 +22,10 @@ module StubExperiments # Examples # - `stub_experiment_for_user(signup_flow: false)` ... Disable `signup_flow` experiment for user. def stub_experiment_for_user(experiments) - allow(Gitlab::Experimentation).to receive(:enabled_for_user?).and_call_original + allow(Gitlab::Experimentation).to receive(:enabled_for_value?).and_call_original experiments.each do |experiment_key, enabled| - allow(Gitlab::Experimentation).to receive(:enabled_for_user?).with(experiment_key, anything) { enabled } + allow(Gitlab::Experimentation).to receive(:enabled_for_value?).with(experiment_key, anything) { enabled } end end end diff --git a/spec/support/helpers/stub_feature_flags.rb b/spec/support/helpers/stub_feature_flags.rb index 792a1c21c31..7f30a2a70cd 100644 --- a/spec/support/helpers/stub_feature_flags.rb +++ b/spec/support/helpers/stub_feature_flags.rb @@ -62,4 +62,8 @@ module StubFeatureFlags StubFeatureGate.new(object) end + + def skip_feature_flags_yaml_validation + allow(Feature::Definition).to receive(:valid_usage!) + end end diff --git a/spec/support/helpers/stub_object_storage.rb b/spec/support/helpers/stub_object_storage.rb index 476b7d34ee5..dba3d2b137e 100644 --- a/spec/support/helpers/stub_object_storage.rb +++ b/spec/support/helpers/stub_object_storage.rb @@ -82,13 +82,27 @@ module StubObjectStorage **params) end - def stub_terraform_state_object_storage(uploader = described_class, **params) + def stub_terraform_state_object_storage(**params) stub_object_storage_uploader(config: Gitlab.config.terraform_state.object_store, - uploader: uploader, + uploader: Terraform::VersionedStateUploader, + remote_directory: 'terraform', + **params) + end + + def stub_terraform_state_version_object_storage(**params) + stub_object_storage_uploader(config: Gitlab.config.terraform_state.object_store, + uploader: Terraform::StateUploader, remote_directory: 'terraform', **params) end + def stub_pages_object_storage(uploader = described_class, **params) + stub_object_storage_uploader(config: Gitlab.config.pages.object_store, + uploader: uploader, + remote_directory: 'pages', + **params) + end + def stub_object_storage_multipart_init(endpoint, upload_id = "upload_id") stub_request(:post, %r{\A#{endpoint}tmp/uploads/[a-z0-9-]*\?uploads\z}) .to_return status: 200, body: <<-EOS.strip_heredoc diff --git a/spec/support/helpers/usage_data_helpers.rb b/spec/support/helpers/usage_data_helpers.rb index d92fcdc2d4a..17e806d21d9 100644 --- a/spec/support/helpers/usage_data_helpers.rb +++ b/spec/support/helpers/usage_data_helpers.rb @@ -99,6 +99,7 @@ module UsageDataHelpers projects_with_error_tracking_enabled projects_with_alerts_service_enabled projects_with_prometheus_alerts + projects_with_tracing_enabled projects_with_expiration_policy_enabled projects_with_expiration_policy_disabled projects_with_expiration_policy_enabled_with_keep_n_unset @@ -133,6 +134,7 @@ module UsageDataHelpers todos uploads web_hooks + user_preferences_user_gitpod_enabled ).push(*SMAU_KEYS) USAGE_DATA_KEYS = %i( @@ -228,7 +230,7 @@ module UsageDataHelpers receive_matchers.each { |m| expect(prometheus_client).to m } end - def for_defined_days_back(days: [29, 2]) + def for_defined_days_back(days: [31, 3]) days.each do |n| Timecop.travel(n.days.ago) do yield diff --git a/spec/support/helpers/wait_for_requests.rb b/spec/support/helpers/wait_for_requests.rb index 2cfd47634ca..43060e571a9 100644 --- a/spec/support/helpers/wait_for_requests.rb +++ b/spec/support/helpers/wait_for_requests.rb @@ -48,17 +48,10 @@ module WaitForRequests def finished_all_js_requests? return true unless javascript_test? - finished_all_ajax_requests? && - finished_all_axios_requests? - end - - def finished_all_axios_requests? - Capybara.page.evaluate_script('window.pendingRequests || 0').zero? # rubocop:disable Style/NumericPredicate + finished_all_ajax_requests? end def finished_all_ajax_requests? - return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"') - - Capybara.page.evaluate_script('jQuery.active').zero? # rubocop:disable Style/NumericPredicate + Capybara.page.evaluate_script('window.pendingRequests || window.pendingRailsUJSRequests || 0').zero? # rubocop:disable Style/NumericPredicate end end diff --git a/spec/support/helpers/wiki_helpers.rb b/spec/support/helpers/wiki_helpers.rb index e59c6bde264..8873a90579d 100644 --- a/spec/support/helpers/wiki_helpers.rb +++ b/spec/support/helpers/wiki_helpers.rb @@ -13,16 +13,16 @@ module WikiHelpers find('.svg-content .js-lazy-loaded') if example.nil? || example.metadata.key?(:js) end - def upload_file_to_wiki(container, user, file_name) - opts = { + def upload_file_to_wiki(wiki, user, file_name) + params = { file_name: file_name, file_content: File.read(expand_fixture_path(file_name)) } ::Wikis::CreateAttachmentService.new( - container: container, + container: wiki.container, current_user: user, - params: opts - ).execute[:result][:file_path] + params: params + ).execute.dig(:result, :file_path) end end |