diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/support/helpers | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/support/helpers')
22 files changed, 381 insertions, 76 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..94996f7480e --- /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) + 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/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb index f4343b8b783..6d3ac699a7c 100644 --- a/spec/support/helpers/cycle_analytics_helpers.rb +++ b/spec/support/helpers/cycle_analytics_helpers.rb @@ -126,17 +126,15 @@ module CycleAnalyticsHelpers end def mock_gitaly_multi_action_dates(repository, commit_time) - allow(repository.raw).to receive(:multi_action).and_wrap_original do |m, *args| + allow(repository.raw).to receive(:multi_action).and_wrap_original do |m, user, kargs| new_date = commit_time || Time.now - branch_update = m.call(*args) + branch_update = m.call(user, **kargs) if branch_update.newrev - _, opts = args - commit = rugged_repo(repository).rev_parse(branch_update.newrev) branch_update.newrev = commit.amend( - update_ref: "#{Gitlab::Git::BRANCH_REF_PREFIX}#{opts[:branch_name]}", + update_ref: "#{Gitlab::Git::BRANCH_REF_PREFIX}#{kargs[:branch_name]}", author: commit.author.merge(time: new_date), committer: commit.committer.merge(time: new_date) ) diff --git a/spec/support/helpers/drag_to_helper.rb b/spec/support/helpers/drag_to_helper.rb index 2e9932f2e8a..692a4d2b30e 100644 --- a/spec/support/helpers/drag_to_helper.rb +++ b/spec/support/helpers/drag_to_helper.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true module DragTo - def drag_to(list_from_index: 0, from_index: 0, to_index: 0, list_to_index: 0, selector: '', scrollable: 'body', duration: 1000, perform_drop: true) + # rubocop:disable Metrics/ParameterLists + def drag_to(list_from_index: 0, from_index: 0, to_index: 0, list_to_index: 0, selector: '', scrollable: 'body', duration: 1000, perform_drop: true, extra_height: 0) js = <<~JS simulateDrag({ scrollable: document.querySelector('#{scrollable}'), @@ -14,7 +15,8 @@ module DragTo el: document.querySelectorAll('#{selector}')[#{list_to_index}], index: #{to_index} }, - performDrop: #{perform_drop} + performDrop: #{perform_drop}, + extraHeight: #{extra_height} }); JS evaluate_script(js) @@ -23,6 +25,7 @@ module DragTo loop while drag_active? end end + # rubocop:enable Metrics/ParameterLists def drag_active? page.evaluate_script('window.SIMULATE_DRAG_ACTIVE').nonzero? diff --git a/spec/support/helpers/features/blob_spec_helpers.rb b/spec/support/helpers/features/blob_spec_helpers.rb new file mode 100644 index 00000000000..880a7249284 --- /dev/null +++ b/spec/support/helpers/features/blob_spec_helpers.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# These helpers help you interact within the blobs page and blobs edit page (Single file editor). +module BlobSpecHelpers + include ActionView::Helpers::JavaScriptHelper + + def set_default_button(type) + evaluate_script("localStorage.setItem('gl-web-ide-button-selected', '#{type}')") + end + + def unset_default_button + set_default_button('') + end + + def editor_value + evaluate_script('monaco.editor.getModels()[0].getValue()') + end + + def set_editor_value(value) + execute_script("monaco.editor.getModels()[0].setValue('#{value}')") + 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/features/snippet_helpers.rb b/spec/support/helpers/features/snippet_helpers.rb index c01d179770c..c26849a9680 100644 --- a/spec/support/helpers/features/snippet_helpers.rb +++ b/spec/support/helpers/features/snippet_helpers.rb @@ -10,39 +10,69 @@ module Spec include ActionView::Helpers::JavaScriptHelper include Spec::Support::Helpers::Features::EditorLiteSpecHelpers + def snippet_description_locator + 'snippet-description' + end + + def snippet_blob_path_locator + 'snippet_file_name' + end + + def snippet_description_view_selector + '.snippet-header .snippet-description' + end + + def snippet_description_field_collapsed + find('.js-description-input').find('input,textarea') + end + def snippet_get_first_blob_path - page.find_field(snippet_blob_path_field, match: :first).value + page.find_field('snippet_file_name', match: :first).value end def snippet_get_first_blob_value - page.find(snippet_blob_content_selector, match: :first) + page.find('.gl-editor-lite', match: :first) end def snippet_description_value - page.find_field(snippet_description_field).value + page.find_field(snippet_description_locator).value + end + + def snippet_fill_in_visibility(text) + page.find('#visibility-level-setting').choose(text) end - def snippet_fill_in_form(title:, content:, description: '') - # fill_in snippet_title_field, with: title - # editor_set_value(content) - fill_in snippet_title_field, with: title + def snippet_fill_in_title(value) + fill_in 'snippet-title', with: value + end - if description - # Click placeholder first to expand full description field - description_field.click - fill_in snippet_description_field, with: description - end + def snippet_fill_in_description(value) + # Click placeholder first to expand full description field + snippet_description_field_collapsed.click + fill_in snippet_description_locator, with: value + end - page.within('.file-editor') do + def snippet_fill_in_content(value) + page.within('.gl-editor-lite') do el = find('.inputarea') - el.send_keys content + el.send_keys value end end - private + def snippet_fill_in_file_name(value) + fill_in(snippet_blob_path_locator, match: :first, with: value) + end + + def snippet_fill_in_form(title: nil, content: nil, file_name: nil, description: nil, visibility: nil) + snippet_fill_in_title(title) if title - def description_field - find('.js-description-input').find('input,textarea') + snippet_fill_in_description(description) if description + + snippet_fill_in_file_name(file_name) if file_name + + snippet_fill_in_content(content) if content + + snippet_fill_in_visibility(visibility) if visibility 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..db769041f1e 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -23,7 +23,7 @@ module GraphqlHelpers return early_return unless ready - resolver.resolve(args) + resolver.resolve(**args) end # Eagerly run a loader's named resolver @@ -219,6 +219,7 @@ module GraphqlHelpers def as_graphql_literal(value) case value when Array then "[#{value.map { |v| as_graphql_literal(v) }.join(',')}]" + when Hash then "{#{attributes_to_graphql(value)}}" when Integer, Float then value.to_s when String then "\"#{value.gsub(/"/, '\\"')}\"" when Symbol then value @@ -234,7 +235,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/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb index 4f11f8c6b24..2224af88ab9 100644 --- a/spec/support/helpers/javascript_fixtures_helpers.rb +++ b/spec/support/helpers/javascript_fixtures_helpers.rb @@ -39,6 +39,17 @@ module JavaScriptFixturesHelpers Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path) end + # Public: Reads a GraphQL query from the filesystem as a string + # + # query_path - file path to the GraphQL query, relative to `app/assets/javascripts` + # fragment_paths - an optional array of file paths to any fragments the query uses, + # also relative to `app/assets/javascripts` + def get_graphql_query_as_string(query_path, fragment_paths = []) + [query_path, *fragment_paths].map do |path| + File.read(File.join(Rails.root, '/app/assets/javascripts', path)) + end.join("\n") + end + private # Private: Store a response object as fixture file diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index 8882f31e2f4..113bb31e4be 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -33,6 +33,10 @@ module KubernetesHelpers kube_response(kube_deployments_body) end + def kube_ingresses_response + kube_response(kube_ingresses_body) + end + def stub_kubeclient_discover_base(api_url) WebMock.stub_request(:get, api_url + '/api/v1').to_return(kube_response(kube_v1_discovery_body)) WebMock @@ -63,6 +67,9 @@ module KubernetesHelpers WebMock .stub_request(:get, api_url + '/apis/serving.knative.dev/v1alpha1') .to_return(kube_response(kube_v1alpha1_serving_knative_discovery_body)) + WebMock + .stub_request(:get, api_url + '/apis/networking.k8s.io/v1') + .to_return(kube_response(kube_v1_networking_discovery_body)) end def stub_kubeclient_discover_knative_not_found(api_url) @@ -148,12 +155,20 @@ module KubernetesHelpers WebMock.stub_request(:get, deployments_url).to_return(response || kube_deployments_response) end + def stub_kubeclient_ingresses(namespace, status: nil) + stub_kubeclient_discover(service.api_url) + ingresses_url = service.api_url + "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses" + response = { status: status } if status + + WebMock.stub_request(:get, ingresses_url).to_return(response || kube_ingresses_response) + end + def stub_kubeclient_knative_services(options = {}) namespace_path = options[:namespace].present? ? "namespaces/#{options[:namespace]}/" : "" 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) @@ -265,7 +280,7 @@ module KubernetesHelpers .to_return(kube_response({})) end - def kube_v1_secret_body(**options) + def kube_v1_secret_body(options) { "kind" => "SecretList", "apiVersion": "v1", @@ -304,6 +319,14 @@ module KubernetesHelpers } end + # From Kubernetes 1.22+ Ingresses are no longer served from apis/extensions + def kube_1_22_extensions_v1beta1_discovery_body + { + "kind" => "APIResourceList", + "resources" => [] + } + end + def kube_knative_discovery_body { "kind" => "APIResourceList", @@ -416,6 +439,17 @@ module KubernetesHelpers } end + def kube_v1_networking_discovery_body + { + "kind" => "APIResourceList", + "apiVersion" => "v1", + "groupVersion" => "networking.k8s.io/v1", + "resources" => [ + { "name" => "ingresses", "namespaced" => true, "kind" => "Ingress" } + ] + } + end + def kube_istio_gateway_body(name, namespace) { "apiVersion" => "networking.istio.io/v1alpha3", @@ -507,6 +541,13 @@ module KubernetesHelpers } end + def kube_ingresses_body + { + "kind" => "List", + "items" => [kube_ingress] + } + end + def kube_knative_pods_body(name, namespace) { "kind" => "PodList", @@ -517,7 +558,7 @@ module KubernetesHelpers def kube_knative_services_body(**options) { "kind" => "List", - "items" => [knative_09_service(options)] + "items" => [knative_09_service(**options)] } end @@ -548,6 +589,38 @@ module KubernetesHelpers } end + def kube_ingress(track: :stable) + additional_annotations = + if track == :canary + { + "nginx.ingress.kubernetes.io/canary" => "true", + "nginx.ingress.kubernetes.io/canary-by-header" => "canary", + "nginx.ingress.kubernetes.io/canary-weight" => "50" + } + else + {} + end + + { + "metadata" => { + "name" => "production-auto-deploy", + "labels" => { + "app" => "production", + "app.kubernetes.io/managed-by" => "Helm", + "chart" => "auto-deploy-app-2.0.0-beta.2", + "heritage" => "Helm", + "release" => "production" + }, + "annotations" => { + "kubernetes.io/ingress.class" => "nginx", + "kubernetes.io/tls-acme" => "true", + "meta.helm.sh/release-name" => "production", + "meta.helm.sh/release-namespace" => "awesome-app-1-production" + }.merge(additional_annotations) + } + } + end + # This is a partial response, it will have many more elements in reality but # these are the ones we care about at the moment def kube_node @@ -604,7 +677,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 +690,7 @@ module KubernetesHelpers "track" => track }.compact }, - "spec" => { "replicas" => 3 }, + "spec" => { "replicas" => replicas }, "status" => { "observedGeneration" => 4 } @@ -862,8 +935,8 @@ module KubernetesHelpers end end - def kube_deployment_rollout_status - ::Gitlab::Kubernetes::RolloutStatus.from_deployments(kube_deployment) + def kube_deployment_rollout_status(ingresses: []) + ::Gitlab::Kubernetes::RolloutStatus.from_deployments(kube_deployment, ingresses: ingresses) end def empty_deployment_rollout_status diff --git a/spec/support/helpers/multipart_helpers.rb b/spec/support/helpers/multipart_helpers.rb index 043cb6e1420..2e8db0e9e42 100644 --- a/spec/support/helpers/multipart_helpers.rb +++ b/spec/support/helpers/multipart_helpers.rb @@ -31,7 +31,7 @@ module MultipartHelpers raise ArgumentError, "can't handle #{mode} mode" end - return result if ::Feature.disabled?(:upload_middleware_jwt_params_handler) + return result if ::Feature.disabled?(:upload_middleware_jwt_params_handler, default_enabled: true) # the HandlerForJWTParams expects a jwt token with the upload parameters # *without* the "#{key}." prefix diff --git a/spec/support/helpers/rack_attack_spec_helpers.rb b/spec/support/helpers/rack_attack_spec_helpers.rb index 65082ec690f..a8ae69885d8 100644 --- a/spec/support/helpers/rack_attack_spec_helpers.rb +++ b/spec/support/helpers/rack_attack_spec_helpers.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true module RackAttackSpecHelpers - def post_args_with_token_headers(url, token_headers) - [url, params: nil, headers: token_headers] - end - def api_get_args_with_token_headers(partial_url, token_headers) ["/api/#{API::API.version}#{partial_url}", params: nil, headers: token_headers] end 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/snippet_helpers.rb b/spec/support/helpers/snippet_helpers.rb index de64ad7d3e2..1ec50bce070 100644 --- a/spec/support/helpers/snippet_helpers.rb +++ b/spec/support/helpers/snippet_helpers.rb @@ -8,7 +8,7 @@ module SnippetHelpers def snippet_blob_file(blob) { "path" => blob.path, - "raw_url" => gitlab_raw_snippet_blob_url(blob.container, blob.path) + "raw_url" => gitlab_raw_snippet_blob_url(blob.container, blob.path, host: 'localhost') } end end diff --git a/spec/support/helpers/snowplow_helpers.rb b/spec/support/helpers/snowplow_helpers.rb index 83a5b7e48bc..3bde01c6fbf 100644 --- a/spec/support/helpers/snowplow_helpers.rb +++ b/spec/support/helpers/snowplow_helpers.rb @@ -32,8 +32,16 @@ module SnowplowHelpers # end # end def expect_snowplow_event(category:, action:, **kwargs) - expect(Gitlab::Tracking).to have_received(:event) - .with(category, action, **kwargs).at_least(:once) + # This check will no longer be needed with Ruby 2.7 which + # would not pass any arguments when using **kwargs. + # https://gitlab.com/gitlab-org/gitlab/-/issues/263430 + if kwargs.present? + expect(Gitlab::Tracking).to have_received(:event) + .with(category, action, **kwargs).at_least(:once) + else + expect(Gitlab::Tracking).to have_received(:event) + .with(category, action).at_least(:once) + end end # Asserts that no call to `Gitlab::Tracking#event` was made. 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/stubbed_feature.rb b/spec/support/helpers/stubbed_feature.rb index d4e9af7a031..67ceb7d9b35 100644 --- a/spec/support/helpers/stubbed_feature.rb +++ b/spec/support/helpers/stubbed_feature.rb @@ -4,6 +4,14 @@ module StubbedFeature extend ActiveSupport::Concern + prepended do + cattr_reader(:persist_used) do + # persist feature flags in CI + # nil: indicates that we do not want to persist used feature flags + Gitlab::Utils.to_boolean(ENV['CI']) ? {} : nil + end + end + class_methods do # Turn stubbed feature flags on or off. def stub=(stub) @@ -29,10 +37,12 @@ module StubbedFeature end # Replace #enabled? method with the optional stubbed/unstubbed version. - def enabled?(*args) - feature_flag = super(*args) + def enabled?(*args, **kwargs) + feature_flag = super return feature_flag unless stub? + persist_used!(args.first) + # If feature flag is not persisted we mark the feature flag as enabled # We do `m.call` as we want to validate the execution of method arguments # and a feature flag state if it is not persisted @@ -42,5 +52,17 @@ module StubbedFeature feature_flag end + + # This method creates a temporary file in `tmp/feature_flags` + # if feature flag was touched during execution + def persist_used!(name) + return unless persist_used + return if persist_used[name] + + persist_used[name] = true + FileUtils.touch( + Rails.root.join('tmp', 'feature_flags', name.to_s + ".used") + ) + end end end diff --git a/spec/support/helpers/usage_data_helpers.rb b/spec/support/helpers/usage_data_helpers.rb index d92fcdc2d4a..2592d9f8b42 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( @@ -171,6 +173,10 @@ module UsageDataHelpers allow(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(false) end + def clear_memoized_values(values) + values.each { |v| described_class.clear_memoization(v) } + end + def stub_object_store_settings allow(Settings).to receive(:[]).with('artifacts') .and_return( @@ -228,9 +234,9 @@ 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 + travel_to(n.days.ago) do yield end end 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 |