diff options
Diffstat (limited to 'spec/support/helpers')
21 files changed, 330 insertions, 29 deletions
diff --git a/spec/support/helpers/board_helpers.rb b/spec/support/helpers/board_helpers.rb index 6e145fed733..c4e69d06f52 100644 --- a/spec/support/helpers/board_helpers.rb +++ b/spec/support/helpers/board_helpers.rb @@ -4,6 +4,23 @@ module BoardHelpers def click_card(card) within card do first('.board-card-number').click + wait_for_requests + end + end + + def load_board(board_path) + visit board_path + + wait_for_requests + end + + def click_card_and_edit_label + click_card(card) + + page.within(labels_select) do + click_button 'Edit' + + wait_for_requests end end end diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb index 9e62eef14de..5510284b30d 100644 --- a/spec/support/helpers/cycle_analytics_helpers.rb +++ b/spec/support/helpers/cycle_analytics_helpers.rb @@ -3,6 +3,38 @@ module CycleAnalyticsHelpers include GitHelpers + def toggle_value_stream_dropdown + page.find('[data-testid="dropdown-value-streams"]').click + end + + def add_custom_stage_to_form + page.find_button(s_('CreateValueStreamForm|Add another stage')).click + + index = page.all('[data-testid="value-stream-stage-fields"]').length + last_stage = page.all('[data-testid="value-stream-stage-fields"]').last + + within last_stage do + find('[name*="custom-stage-name-"]').fill_in with: "Cool custom stage - name #{index}" + select_dropdown_option_by_value "custom-stage-start-event-", :merge_request_created + select_dropdown_option_by_value "custom-stage-end-event-", :merge_request_merged + end + end + + def save_value_stream(custom_value_stream_name) + fill_in 'create-value-stream-name', with: custom_value_stream_name + + page.find_button(s_('CreateValueStreamForm|Create Value Stream')).click + wait_for_requests + end + + def create_custom_value_stream(custom_value_stream_name) + toggle_value_stream_dropdown + page.find_button(_('Create new Value Stream')).click + + add_custom_stage_to_form + save_value_stream(custom_value_stream_name) + end + def wait_for_stages_to_load(selector = '.js-path-navigation') expect(page).to have_selector selector wait_for_requests @@ -93,17 +125,17 @@ module CycleAnalyticsHelpers target_branch: 'master' } - mr = MergeRequests::CreateService.new(project, user, opts).execute + mr = MergeRequests::CreateService.new(project: project, current_user: user, params: opts).execute NewMergeRequestWorker.new.perform(mr, user) mr end def merge_merge_requests_closing_issue(user, project, issue) merge_requests = Issues::ReferencedMergeRequestsService - .new(project, user) + .new(project: project, current_user: user) .closed_by_merge_requests(issue) - merge_requests.each { |merge_request| MergeRequests::MergeService.new(project, user, sha: merge_request.diff_head_sha).execute(merge_request) } + merge_requests.each { |merge_request| MergeRequests::MergeService.new(project: project, current_user: user, params: { sha: merge_request.diff_head_sha }).execute(merge_request) } end def deploy_master(user, project, environment: 'production') diff --git a/spec/support/helpers/dns_helpers.rb b/spec/support/helpers/dns_helpers.rb index 1795b0a9ac3..ba32ccbb6f1 100644 --- a/spec/support/helpers/dns_helpers.rb +++ b/spec/support/helpers/dns_helpers.rb @@ -18,7 +18,7 @@ module DnsHelpers def stub_invalid_dns! allow(Addrinfo).to receive(:getaddrinfo).with(/\Afoobar\.\w|(\d{1,3}\.){4,}\d{1,3}\z/i, anything, nil, :STREAM) do - raise SocketError.new("getaddrinfo: Name or service not known") + raise SocketError, "getaddrinfo: Name or service not known" end end diff --git a/spec/support/helpers/features/invite_members_modal_helper.rb b/spec/support/helpers/features/invite_members_modal_helper.rb new file mode 100644 index 00000000000..1127c817656 --- /dev/null +++ b/spec/support/helpers/features/invite_members_modal_helper.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Spec + module Support + module Helpers + module Features + module InviteMembersModalHelper + def invite_member(name, role: 'Guest', expires_at: nil) + click_on 'Invite members' + + page.within '#invite-members-modal' do + fill_in 'Select members or type email addresses', with: name + + wait_for_requests + click_button name + choose_options(role, expires_at) + + click_button 'Invite' + + page.refresh + end + end + + def invite_group(name, role: 'Guest', expires_at: nil) + click_on 'Invite a group' + + click_on 'Select a group' + wait_for_requests + click_button name + choose_options(role, expires_at) + + click_button 'Invite' + + page.refresh + end + + def choose_options(role, expires_at) + unless role == 'Guest' + click_button 'Guest' + wait_for_requests + click_button role + end + + fill_in 'YYYY-MM-DD', with: expires_at.try(:strftime, '%Y-%m-%d') + end + end + end + end + end +end diff --git a/spec/support/helpers/features/members_table_helpers.rb b/spec/support/helpers/features/members_table_helpers.rb index 4a0e218ed3e..2e86e014a1b 100644 --- a/spec/support/helpers/features/members_table_helpers.rb +++ b/spec/support/helpers/features/members_table_helpers.rb @@ -27,10 +27,6 @@ module Spec all_rows[2] end - def invite_users_form - page.find('[data-testid="invite-users-form"]') - end - def find_row(name) page.within(members_table) do page.find('tbody > tr', text: name) diff --git a/spec/support/helpers/gitaly_setup.rb b/spec/support/helpers/gitaly_setup.rb new file mode 100644 index 00000000000..2ce4bcfa943 --- /dev/null +++ b/spec/support/helpers/gitaly_setup.rb @@ -0,0 +1,195 @@ +# frozen_string_literal: true + +# This file contains environment settings for gitaly when it's running +# as part of the gitlab-ce/ee test suite. +# +# Please be careful when modifying this file. Your changes must work +# both for local development rspec runs, and in CI. + +require 'securerandom' +require 'socket' +require 'logger' + +module GitalySetup + LOGGER = begin + default_name = ENV['CI'] ? 'DEBUG' : 'WARN' + level_name = ENV['GITLAB_TESTING_LOG_LEVEL']&.upcase + level = Logger.const_get(level_name || default_name, true) # rubocop: disable Gitlab/ConstGetInheritFalse + Logger.new(STDOUT, level: level, formatter: ->(_, _, _, msg) { msg }) + end + + def tmp_tests_gitaly_dir + File.expand_path('../../../tmp/tests/gitaly', __dir__) + end + + def tmp_tests_gitaly_bin_dir + File.join(tmp_tests_gitaly_dir, '_build', 'bin') + end + + def tmp_tests_gitlab_shell_dir + File.expand_path('../../../tmp/tests/gitlab-shell', __dir__) + end + + def rails_gitlab_shell_secret + File.expand_path('../../../.gitlab_shell_secret', __dir__) + end + + def gemfile + File.join(tmp_tests_gitaly_dir, 'ruby', 'Gemfile') + end + + def gemfile_dir + File.dirname(gemfile) + end + + def gitlab_shell_secret_file + File.join(tmp_tests_gitlab_shell_dir, '.gitlab_shell_secret') + end + + def env + { + 'HOME' => File.expand_path('tmp/tests'), + 'GEM_PATH' => Gem.path.join(':'), + 'BUNDLE_APP_CONFIG' => File.join(gemfile_dir, '.bundle'), + 'BUNDLE_INSTALL_FLAGS' => nil, + 'BUNDLE_GEMFILE' => gemfile, + 'RUBYOPT' => nil, + + # Git hooks can't run during tests as the internal API is not running. + 'GITALY_TESTING_NO_GIT_HOOKS' => "1", + 'GITALY_TESTING_ENABLE_ALL_FEATURE_FLAGS' => "true" + } + end + + # rubocop:disable GitlabSecurity/SystemCommandInjection + def set_bundler_config + system('bundle config set --local jobs 4', chdir: gemfile_dir) + system('bundle config set --local retry 3', chdir: gemfile_dir) + + if ENV['CI'] + bundle_path = File.expand_path('../../../vendor/gitaly-ruby', __dir__) + system('bundle', 'config', 'set', '--local', 'path', bundle_path, chdir: gemfile_dir) + end + end + # rubocop:enable GitlabSecurity/SystemCommandInjection + + def config_path(service) + case service + when :gitaly + File.join(tmp_tests_gitaly_dir, 'config.toml') + when :gitaly2 + File.join(tmp_tests_gitaly_dir, 'gitaly2.config.toml') + when :praefect + File.join(tmp_tests_gitaly_dir, 'praefect.config.toml') + end + end + + def service_binary(service) + case service + when :gitaly, :gitaly2 + 'gitaly' + when :praefect + 'praefect' + end + end + + def install_gitaly_gems + system(env, "make #{tmp_tests_gitaly_dir}/.ruby-bundle", chdir: tmp_tests_gitaly_dir) # rubocop:disable GitlabSecurity/SystemCommandInjection + end + + def build_gitaly + system(env, 'make', chdir: tmp_tests_gitaly_dir) # rubocop:disable GitlabSecurity/SystemCommandInjection + end + + def start_gitaly + start(:gitaly) + end + + def start_gitaly2 + start(:gitaly2) + end + + def start_praefect + start(:praefect) + end + + def start(service) + args = ["#{tmp_tests_gitaly_bin_dir}/#{service_binary(service)}"] + args.push("-config") if service == :praefect + args.push(config_path(service)) + pid = spawn(env, *args, [:out, :err] => "log/#{service}-test.log") + + begin + try_connect!(service) + rescue StandardError + Process.kill('TERM', pid) + raise + end + + pid + end + + # Taken from Gitlab::Shell.generate_and_link_secret_token + def ensure_gitlab_shell_secret! + secret_file = rails_gitlab_shell_secret + shell_link = gitlab_shell_secret_file + + unless File.size?(secret_file) + File.write(secret_file, SecureRandom.hex(16)) + end + + unless File.exist?(shell_link) + FileUtils.ln_s(secret_file, shell_link) + end + end + + def check_gitaly_config! + LOGGER.debug "Checking gitaly-ruby Gemfile...\n" + + unless File.exist?(gemfile) + message = "#{gemfile} does not exist." + message += "\n\nThis might have happened if the CI artifacts for this build were destroyed." if ENV['CI'] + abort message + end + + LOGGER.debug "Checking gitaly-ruby bundle...\n" + out = ENV['CI'] ? STDOUT : '/dev/null' + abort 'bundle check failed' unless system(env, 'bundle', 'check', out: out, chdir: File.dirname(gemfile)) + end + + def read_socket_path(service) + # This code needs to work in an environment where we cannot use bundler, + # so we cannot easily use the toml-rb gem. This ad-hoc parser should be + # good enough. + config_text = IO.read(config_path(service)) + + config_text.lines.each do |line| + match_data = line.match(/^\s*socket_path\s*=\s*"([^"]*)"$/) + + return match_data[1] if match_data + end + + raise "failed to find socket_path in #{config_path(service)}" + end + + def try_connect!(service) + LOGGER.debug "Trying to connect to #{service}: " + timeout = 20 + delay = 0.1 + socket = read_socket_path(service) + + Integer(timeout / delay).times do + UNIXSocket.new(socket) + LOGGER.debug " OK\n" + + return + rescue Errno::ENOENT, Errno::ECONNREFUSED + LOGGER.debug '.' + sleep delay + end + + LOGGER.warn " FAILED to connect to #{service}\n" + + raise "could not connect to #{socket}" + end +end diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 9d6c6ab93e4..5dc6945ec5e 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -142,9 +142,9 @@ module GraphqlHelpers Class.new(::Types::BaseObject) { graphql_name name } end - def resolver_instance(resolver_class, obj: nil, ctx: {}, field: nil, schema: GitlabSchema) + def resolver_instance(resolver_class, obj: nil, ctx: {}, field: nil, schema: GitlabSchema, subscription_update: false) if ctx.is_a?(Hash) - q = double('Query', schema: schema) + q = double('Query', schema: schema, subscription_update?: subscription_update) ctx = GraphQL::Query::Context.new(query: q, object: obj, values: ctx) end diff --git a/spec/support/helpers/ldap_helpers.rb b/spec/support/helpers/ldap_helpers.rb index 8154e3a4fc9..2f5f8be518c 100644 --- a/spec/support/helpers/ldap_helpers.rb +++ b/spec/support/helpers/ldap_helpers.rb @@ -71,4 +71,4 @@ module LdapHelpers end end -LdapHelpers.include_if_ee('EE::LdapHelpers') +LdapHelpers.include_mod_with('LdapHelpers') diff --git a/spec/support/helpers/license_helper.rb b/spec/support/helpers/license_helper.rb index a1defba9ccb..61afb2171f0 100644 --- a/spec/support/helpers/license_helper.rb +++ b/spec/support/helpers/license_helper.rb @@ -7,4 +7,4 @@ module LicenseHelpers end end -LicenseHelpers.prepend_if_ee('EE::LicenseHelpers') +LicenseHelpers.prepend_mod_with('LicenseHelpers') diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index 86022e16d71..fc3eb976276 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -237,4 +237,4 @@ module LoginHelpers end end -LoginHelpers.prepend_if_ee('EE::LoginHelpers') +LoginHelpers.prepend_mod_with('LoginHelpers') diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index 2c31a608b35..fa50b234bd5 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -172,4 +172,4 @@ module MigrationsHelpers end end -MigrationsHelpers.prepend_if_ee('EE::MigrationsHelpers') +MigrationsHelpers.prepend_mod_with('MigrationsHelpers') diff --git a/spec/support/helpers/next_found_instance_of.rb b/spec/support/helpers/next_found_instance_of.rb index feb63f90211..c8cdbaf2c5d 100644 --- a/spec/support/helpers/next_found_instance_of.rb +++ b/spec/support/helpers/next_found_instance_of.rb @@ -22,7 +22,7 @@ module NextFoundInstanceOf private def check_if_active_record!(klass) - raise ArgumentError.new(ERROR_MESSAGE) unless klass < ActiveRecord::Base + raise ArgumentError, ERROR_MESSAGE unless klass < ActiveRecord::Base end def stub_allocate(target, klass) diff --git a/spec/support/helpers/query_recorder.rb b/spec/support/helpers/query_recorder.rb index 2d880c7a8fe..05afbc336da 100644 --- a/spec/support/helpers/query_recorder.rb +++ b/spec/support/helpers/query_recorder.rb @@ -13,6 +13,10 @@ module ActiveRecord @skip_cached = skip_cached @query_recorder_debug = ENV['QUERY_RECORDER_DEBUG'] || query_recorder_debug @log_file = log_file + record(&block) if block_given? + end + + def record(&block) # force replacement of bind parameters to give tests the ability to check for ids ActiveRecord::Base.connection.unprepared_statement do ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) diff --git a/spec/support/helpers/redis_without_keys.rb b/spec/support/helpers/redis_without_keys.rb index e030f1028f7..ff64a3cf08e 100644 --- a/spec/support/helpers/redis_without_keys.rb +++ b/spec/support/helpers/redis_without_keys.rb @@ -4,7 +4,7 @@ class Redis ForbiddenCommand = Class.new(StandardError) def keys(*args) - raise ForbiddenCommand.new("Don't use `Redis#keys` as it iterates over all "\ - "keys in redis. Use `Redis#scan_each` instead.") + raise ForbiddenCommand, "Don't use `Redis#keys` as it iterates over all "\ + "keys in redis. Use `Redis#scan_each` instead." end end diff --git a/spec/support/helpers/reload_helpers.rb b/spec/support/helpers/reload_helpers.rb index 60811e4604f..368ebaaba8a 100644 --- a/spec/support/helpers/reload_helpers.rb +++ b/spec/support/helpers/reload_helpers.rb @@ -2,7 +2,7 @@ module ReloadHelpers def reload_models(*models) - models.map(&:reload) + models.compact.map(&:reload) end def subject_and_reload(*models) diff --git a/spec/support/helpers/require_migration.rb b/spec/support/helpers/require_migration.rb index c2902aa4ec7..8de71d3073f 100644 --- a/spec/support/helpers/require_migration.rb +++ b/spec/support/helpers/require_migration.rb @@ -20,7 +20,7 @@ class RequireMigration class << self def require_migration!(file_name) file_paths = search_migration_file(file_name) - raise AutoLoadError.new(file_name) unless file_paths.first + raise AutoLoadError, file_name unless file_paths.first require file_paths.first end @@ -41,7 +41,7 @@ class RequireMigration end end -RequireMigration.prepend_if_ee('EE::RequireMigration') +RequireMigration.prepend_mod_with('RequireMigration') def require_migration!(file_name = nil) location_info = caller_locations.first.path.match(RequireMigration::SPEC_FILE_PATTERN) diff --git a/spec/support/helpers/snowplow_helpers.rb b/spec/support/helpers/snowplow_helpers.rb index 70a4eadd8de..553739b5d30 100644 --- a/spec/support/helpers/snowplow_helpers.rb +++ b/spec/support/helpers/snowplow_helpers.rb @@ -60,6 +60,10 @@ module SnowplowHelpers .with(category, action, **kwargs).at_least(:once) end + def match_snowplow_context_schema(schema_path:, context:) + expect(context).to match_snowplow_schema(schema_path) + end + # Asserts that no call to `Gitlab::Tracking#event` was made. # # Example: @@ -71,7 +75,11 @@ module SnowplowHelpers # expect_no_snowplow_event # end # end - def expect_no_snowplow_event - expect(Gitlab::Tracking).not_to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking + def expect_no_snowplow_event(category: nil, action: nil, **kwargs) + if category && action + expect(Gitlab::Tracking).not_to have_received(:event).with(category, action, **kwargs) # rubocop:disable RSpec/ExpectGitlabTracking + else + expect(Gitlab::Tracking).not_to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking + end end end diff --git a/spec/support/helpers/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb index 9851a3de9e9..8c60dc30cdb 100644 --- a/spec/support/helpers/stub_configuration.rb +++ b/spec/support/helpers/stub_configuration.rb @@ -163,4 +163,4 @@ end require_relative '../../../ee/spec/support/helpers/ee/stub_configuration' if Dir.exist?("#{__dir__}/../../../ee") -StubConfiguration.prepend_if_ee('EE::StubConfiguration') +StubConfiguration.prepend_mod_with('StubConfiguration') diff --git a/spec/support/helpers/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb index 4da8f760056..3824ff2b68d 100644 --- a/spec/support/helpers/stub_gitlab_calls.rb +++ b/spec/support/helpers/stub_gitlab_calls.rb @@ -153,4 +153,4 @@ module StubGitlabCalls end end -StubGitlabCalls.prepend_if_ee('EE::StubGitlabCalls') +StubGitlabCalls.prepend_mod_with('StubGitlabCalls') diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index 7ba15a9c00b..40a3dbfbf25 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -52,7 +52,7 @@ module TestEnv 'wip' => 'b9238ee', 'csv' => '3dd0896', 'v1.1.0' => 'b83d6e3', - 'add-ipython-files' => '93ee732', + 'add-ipython-files' => 'f6b7a70', 'add-pdf-file' => 'e774ebd', 'squash-large-files' => '54cec52', 'add-pdf-text-binary' => '79faa7b', @@ -266,7 +266,7 @@ module TestEnv Integer(sleep_time / sleep_interval).times do Socket.unix(socket) return - rescue + rescue StandardError sleep sleep_interval end @@ -612,5 +612,5 @@ end require_relative('../../../ee/spec/support/helpers/ee/test_env') if Gitlab.ee? -::TestEnv.prepend_if_ee('::EE::TestEnv') -::TestEnv.extend_if_ee('::EE::TestEnv') +::TestEnv.prepend_mod_with('TestEnv') +::TestEnv.extend_mod_with('TestEnv') diff --git a/spec/support/helpers/usage_data_helpers.rb b/spec/support/helpers/usage_data_helpers.rb index d05676a649e..c6176b5bcbc 100644 --- a/spec/support/helpers/usage_data_helpers.rb +++ b/spec/support/helpers/usage_data_helpers.rb @@ -98,7 +98,6 @@ module UsageDataHelpers projects_prometheus_active projects_with_repositories_enabled projects_with_error_tracking_enabled - projects_with_alerts_service_enabled projects_with_enabled_alert_integrations projects_with_prometheus_alerts projects_with_tracing_enabled |