diff options
Diffstat (limited to 'spec/support/helpers')
-rw-r--r-- | spec/support/helpers/content_editor_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/features/dom_helpers.rb | 13 | ||||
-rw-r--r-- | spec/support/helpers/features/runners_helpers.rb | 13 | ||||
-rw-r--r-- | spec/support/helpers/filter_spec_helper.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/kubernetes_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/helpers/metrics_dashboard_helpers.rb | 8 | ||||
-rw-r--r-- | spec/support/helpers/migrations_helpers/project_statistics_helper.rb | 37 | ||||
-rw-r--r-- | spec/support/helpers/models/ci/partitioning_testing/rspec_hooks.rb | 12 | ||||
-rw-r--r-- | spec/support/helpers/models/ci/partitioning_testing/schema_helpers.rb | 35 | ||||
-rw-r--r-- | spec/support/helpers/prometheus_helpers.rb | 22 | ||||
-rw-r--r-- | spec/support/helpers/stub_gitlab_calls.rb | 4 |
12 files changed, 96 insertions, 64 deletions
diff --git a/spec/support/helpers/content_editor_helpers.rb b/spec/support/helpers/content_editor_helpers.rb index a6cc2560d0b..7597a13e475 100644 --- a/spec/support/helpers/content_editor_helpers.rb +++ b/spec/support/helpers/content_editor_helpers.rb @@ -9,6 +9,10 @@ module ContentEditorHelpers end end + def switch_to_markdown_editor + click_button("Switch to plain text editing") + end + def switch_to_content_editor click_button("Switch to rich text editing") end diff --git a/spec/support/helpers/features/dom_helpers.rb b/spec/support/helpers/features/dom_helpers.rb new file mode 100644 index 00000000000..ac6523f3360 --- /dev/null +++ b/spec/support/helpers/features/dom_helpers.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Features + module DomHelpers + def find_by_testid(testid) + page.find("[data-testid='#{testid}']") + end + + def within_testid(testid, &block) + page.within("[data-testid='#{testid}']", &block) + end + end +end diff --git a/spec/support/helpers/features/runners_helpers.rb b/spec/support/helpers/features/runners_helpers.rb index 0504e883b82..dbd1edade8c 100644 --- a/spec/support/helpers/features/runners_helpers.rb +++ b/spec/support/helpers/features/runners_helpers.rb @@ -23,11 +23,11 @@ module Features def input_filtered_search_keys(search_term) focus_filtered_search - page.within(search_bar_selector) do - page.find('input').send_keys(search_term) - click_on 'Search' - end + page.find(search_bar_selector).find('input').send_keys(search_term) + # blur input + find('body').click + page.click_on 'Search' wait_for_requests end @@ -49,9 +49,8 @@ module Features # For OPERATORS_IS, clicking the filter # immediately preselects "=" operator - - page.find('input').send_keys(value) - page.find('input').send_keys(:enter) + send_keys(value) + send_keys(:enter) click_on 'Search' end diff --git a/spec/support/helpers/filter_spec_helper.rb b/spec/support/helpers/filter_spec_helper.rb index 7beed9c7755..dc282bf0a68 100644 --- a/spec/support/helpers/filter_spec_helper.rb +++ b/spec/support/helpers/filter_spec_helper.rb @@ -94,9 +94,9 @@ module FilterSpecHelper when /\A(.+)?[^\d]\d+\z/ # Integer-based reference with optional project prefix reference.gsub(/\d+\z/) { |i| i.to_i + 10_000 } - when /\A(.+@)?(\h{7,40}\z)/ + when /\A(.+@)?(#{Gitlab::Git::Commit::RAW_SHA_PATTERN}\z)/o # SHA-based reference with optional prefix - reference.gsub(/\h{7,40}\z/) { |v| v.reverse } + reference.gsub(/#{Gitlab::Git::Commit::RAW_SHA_PATTERN}\z/o) { |v| v.reverse } else reference.gsub(/\w+\z/) { |v| v.reverse } end diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 62e05129fb2..19a637d4893 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -151,7 +151,7 @@ module GraphqlHelpers raise UnauthorizedObject unless parent # we enable the request store so we can track gitaly calls. - ::Gitlab::WithRequestStore.with_request_store do + ::Gitlab::SafeRequestStore.ensure_request_store do prepared_args = case arg_style when :internal_prepared args_internal_prepared(field, args: args, query_ctx: query_ctx, parent: parent, extras: extras, query: query) @@ -267,7 +267,7 @@ module GraphqlHelpers # authentication (token set-up, license checks) # It clears the request store, rails cache, and BatchLoader Executor between runs. def run_with_clean_state(query, **args) - ::Gitlab::WithRequestStore.with_request_store do + ::Gitlab::SafeRequestStore.ensure_request_store do with_clean_rails_cache do with_clean_batchloader_executor do ::GitlabSchema.execute(query, **args) diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index c3076a2c359..92a49d6a196 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -676,7 +676,6 @@ module KubernetesHelpers } end - # noinspection RubyStringKeysInHashInspection def knative_06_service(name: 'kubetest', namespace: 'default', domain: 'example.com', description: 'a knative service', environment: 'production', cluster_id: 9) { "apiVersion" => "serving.knative.dev/v1alpha1", "kind" => "Service", @@ -736,7 +735,6 @@ module KubernetesHelpers "podcount" => 0 } end - # noinspection RubyStringKeysInHashInspection def knative_07_service(name: 'kubetest', namespace: 'default', domain: 'example.com', description: 'a knative service', environment: 'production', cluster_id: 5) { "apiVersion" => "serving.knative.dev/v1alpha1", "kind" => "Service", @@ -788,7 +786,6 @@ module KubernetesHelpers "podcount" => 0 } end - # noinspection RubyStringKeysInHashInspection def knative_09_service(name: 'kubetest', namespace: 'default', domain: 'example.com', description: 'a knative service', environment: 'production', cluster_id: 5) { "apiVersion" => "serving.knative.dev/v1alpha1", "kind" => "Service", @@ -840,7 +837,6 @@ module KubernetesHelpers "podcount" => 0 } end - # noinspection RubyStringKeysInHashInspection def knative_05_service(name: 'kubetest', namespace: 'default', domain: 'example.com', description: 'a knative service', environment: 'production', cluster_id: 8) { "apiVersion" => "serving.knative.dev/v1alpha1", "kind" => "Service", diff --git a/spec/support/helpers/metrics_dashboard_helpers.rb b/spec/support/helpers/metrics_dashboard_helpers.rb index 417baeda33a..1aae3964669 100644 --- a/spec/support/helpers/metrics_dashboard_helpers.rb +++ b/spec/support/helpers/metrics_dashboard_helpers.rb @@ -38,14 +38,6 @@ module MetricsDashboardHelpers ::Gitlab::Config::Loader::Yaml.new(data).load_raw! end - def system_dashboard_path - Metrics::Dashboard::SystemDashboardService::DASHBOARD_PATH - end - - def pod_dashboard_path - Metrics::Dashboard::PodDashboardService::DASHBOARD_PATH - end - def business_metric_title Enums::PrometheusMetric.group_details[:business][:group_title] end diff --git a/spec/support/helpers/migrations_helpers/project_statistics_helper.rb b/spec/support/helpers/migrations_helpers/project_statistics_helper.rb new file mode 100644 index 00000000000..4e7d83a38ac --- /dev/null +++ b/spec/support/helpers/migrations_helpers/project_statistics_helper.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module MigrationHelpers + module ProjectStatisticsHelper + def generate_records(projects, table, values = {}) + projects.map do |proj| + table.create!( + values.merge({ + project_id: proj.id, + namespace_id: proj.namespace_id + }) + ) + end + end + + def create_migration(end_id:) + described_class.new(start_id: 1, end_id: end_id, + batch_table: 'project_statistics', batch_column: 'project_id', + sub_batch_size: 1_000, pause_ms: 0, + connection: ApplicationRecord.connection) + end + + def create_project_stats(project_table, namespace, default_stats, override_stats = {}) + stats = default_stats.merge(override_stats) + + group = namespace.create!(name: 'group_a', path: 'group-a', type: 'Group') + project_namespace = namespace.create!(name: 'project_a', path: 'project_a', type: 'Project', parent_id: group.id) + proj = project_table.create!(name: 'project_a', path: 'project-a', namespace_id: group.id, + project_namespace_id: project_namespace.id) + project_statistics_table.create!( + project_id: proj.id, + namespace_id: group.id, + **stats + ) + end + end +end diff --git a/spec/support/helpers/models/ci/partitioning_testing/rspec_hooks.rb b/spec/support/helpers/models/ci/partitioning_testing/rspec_hooks.rb index 3f0a2bb7f3b..a764e751bf5 100644 --- a/spec/support/helpers/models/ci/partitioning_testing/rspec_hooks.rb +++ b/spec/support/helpers/models/ci/partitioning_testing/rspec_hooks.rb @@ -1,23 +1,19 @@ # frozen_string_literal: true RSpec.configure do |config| - config.include Ci::PartitioningTesting::PartitionIdentifiers + config.include ::Ci::PartitioningTesting::PartitionIdentifiers config.around(:each, :ci_partitionable) do |example| - unless Ci::Build.table_name.to_s.starts_with?('p_') - skip 'Skipping partitioning tests until `ci_builds` is partitioned' - end - - Ci::PartitioningTesting::SchemaHelpers.with_routing_tables do + ::Ci::PartitioningTesting::SchemaHelpers.with_routing_tables do example.run end end config.before(:all) do - Ci::PartitioningTesting::SchemaHelpers.setup + ::Ci::PartitioningTesting::SchemaHelpers.setup end config.after(:all) do - Ci::PartitioningTesting::SchemaHelpers.teardown + ::Ci::PartitioningTesting::SchemaHelpers.teardown end end diff --git a/spec/support/helpers/models/ci/partitioning_testing/schema_helpers.rb b/spec/support/helpers/models/ci/partitioning_testing/schema_helpers.rb index 849d9ea117e..a47aaffdb43 100644 --- a/spec/support/helpers/models/ci/partitioning_testing/schema_helpers.rb +++ b/spec/support/helpers/models/ci/partitioning_testing/schema_helpers.rb @@ -3,36 +3,27 @@ module Ci module PartitioningTesting module SchemaHelpers - DEFAULT_PARTITION = 100 - module_function def with_routing_tables - # model.table_name = :routing_table + # previous_table_name = Model.table_name + # Model.table_name = routing_table_name + yield # ensure - # model.table_name = :regular_table + # Model.table_name = previous_table_name end - # We're dropping the default values here to ensure that the application code - # populates the `partition_id` value and it's not falling back on the - # database default one. We should be able to clean this up after - # partitioning the tables and substituting the routing table in the model: - # https://gitlab.com/gitlab-org/gitlab/-/issues/377822 - # def setup(connection: Ci::ApplicationRecord.connection) each_partitionable_table do |table_name| - change_column_default(table_name, from: DEFAULT_PARTITION, to: nil, connection: connection) - change_column_default("p_#{table_name}", from: DEFAULT_PARTITION, to: nil, connection: connection) create_test_partition("p_#{table_name}", connection: connection) end + ensure_builds_id_uniquness(connection: connection) end def teardown(connection: Ci::ApplicationRecord.connection) each_partitionable_table do |table_name| drop_test_partition("p_#{table_name}", connection: connection) - change_column_default(table_name, from: nil, to: DEFAULT_PARTITION, connection: connection) - change_column_default("p_#{table_name}", from: nil, to: DEFAULT_PARTITION, connection: connection) end end @@ -47,12 +38,6 @@ module Ci end end - def change_column_default(table_name, from:, to:, connection:) - return unless table_available?(table_name, connection: connection) - - connection.change_column_default(table_name, :partition_id, from: from, to: to) - end - def create_test_partition(table_name, connection:) return unless table_available?(table_name, connection: connection) @@ -75,6 +60,16 @@ module Ci SQL end + # This can be removed after https://gitlab.com/gitlab-org/gitlab/-/issues/421173 + # is implemented + def ensure_builds_id_uniquness(connection:) + connection.execute(<<~SQL.squish) + CREATE TRIGGER assign_p_ci_builds_id_trigger + BEFORE INSERT ON #{full_partition_name('ci_builds')} + FOR EACH ROW EXECUTE FUNCTION assign_p_ci_builds_id_value(); + SQL + end + def table_available?(table_name, connection:) connection.table_exists?(table_name) && connection.column_exists?(table_name, :partition_id) diff --git a/spec/support/helpers/prometheus_helpers.rb b/spec/support/helpers/prometheus_helpers.rb index e1f5e6dee14..da80f6f08c2 100644 --- a/spec/support/helpers/prometheus_helpers.rb +++ b/spec/support/helpers/prometheus_helpers.rb @@ -240,12 +240,11 @@ module PrometheusHelpers def prometheus_alert_payload(firing: [], resolved: []) status = firing.any? ? 'firing' : 'resolved' alerts = firing + resolved - alert_name = alerts.first&.title || '' - prometheus_metric_id = alerts.first&.prometheus_metric_id&.to_s + alert_name = alerts.first || '' alerts_map = \ - firing.map { |alert| prometheus_map_alert_payload('firing', alert) } + - resolved.map { |alert| prometheus_map_alert_payload('resolved', alert) } + firing.map { |title| prometheus_map_alert_payload('firing', title) } + + resolved.map { |title| prometheus_map_alert_payload('resolved', title) } # See https://prometheus.io/docs/alerting/configuration/#%3Cwebhook_config%3E { @@ -257,9 +256,7 @@ module PrometheusHelpers 'alertname' => alert_name }, 'commonLabels' => { - 'alertname' => alert_name, - 'gitlab' => 'hook', - 'gitlab_alert_id' => prometheus_metric_id + 'alertname' => alert_name }, 'commonAnnotations' => {}, 'externalURL' => '', @@ -267,22 +264,21 @@ module PrometheusHelpers } end - def prometheus_alert_payload_fingerprint(prometheus_alert) + def prometheus_alert_payload_fingerprint(title) # timestamp is hard-coded in #prometheus_map_alert_payload - fingerprint = "#{prometheus_alert.prometheus_metric_id}/2018-09-24T08:57:31.095725221Z" + # sample fingerprint format comes from AlertManagement::Payload::Prometheus + fingerprint = ["2018-09-24T08:57:31.095725221Z", title].join('/') Gitlab::AlertManagement::Fingerprint.generate(fingerprint) end private - def prometheus_map_alert_payload(status, alert) + def prometheus_map_alert_payload(status, title) { 'status' => status, 'labels' => { - 'alertname' => alert.title, - 'gitlab' => 'hook', - 'gitlab_alert_id' => alert.prometheus_metric_id.to_s + 'alertname' => title }, 'annotations' => {}, 'startsAt' => '2018-09-24T08:57:31.095725221Z', diff --git a/spec/support/helpers/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb index 748ea525e40..6d0e97b0a75 100644 --- a/spec/support/helpers/stub_gitlab_calls.rb +++ b/spec/support/helpers/stub_gitlab_calls.rb @@ -23,6 +23,10 @@ module StubGitlabCalls end def stub_ci_pipeline_yaml_file(ci_yaml_content) + allow_any_instance_of(Gitlab::Ci::ProjectConfig::Repository) + .to receive(:file_in_repository?) + .and_return(ci_yaml_content.present?) + allow_any_instance_of(Repository) .to receive(:gitlab_ci_yml_for) .and_return(ci_yaml_content) |