diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 03:07:10 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 03:07:10 +0000 |
| commit | 9bf8cb8d34039f3cef9e1b2f812ce634f2bebe69 (patch) | |
| tree | c1e4d7a8dc008004b3e3861a4d8f6d9439ffabf8 /spec/support | |
| parent | e91080371b32e69d038b3a94261688c09dbcd641 (diff) | |
| download | gitlab-ce-9bf8cb8d34039f3cef9e1b2f812ce634f2bebe69.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
4 files changed, 68 insertions, 48 deletions
diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index 1b8c3388051..0084835ff8d 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -130,19 +130,45 @@ module MigrationsHelpers end end - def schema_migrate_down! + # TODO: use Gitlab::Database::EachDatabase class (https://gitlab.com/gitlab-org/gitlab/-/issues/410154) + def migrate_databases!(only_databases: nil, version: nil) + only_databases ||= if Gitlab::Database.database_mode == Gitlab::Database::MODE_SINGLE_DATABASE + [:main] + else + %i[main ci] + end + + # unique in the context of database, host, port + configurations = Gitlab::Database.database_base_models.each_with_object({}) do |(_name, model), h| + config = model.connection_db_config + + h[config.configuration_hash.slice(:database, :host, :port)] ||= config + end + + with_reestablished_active_record_base do + configurations.each_value do |configuration| + next unless only_databases.include? configuration.name.to_sym + + ActiveRecord::Base.establish_connection(configuration) # rubocop:disable Database/EstablishConnection + + migration_context.migrate(version) # rubocop:disable Database/MultipleDatabases + end + end + end + + def schema_migrate_down!(only_databases: nil) disable_migrations_output do - migration_context.down(migration_schema_version) + migrate_databases!(only_databases: only_databases, version: migration_schema_version) end reset_column_in_all_models end - def schema_migrate_up! + def schema_migrate_up!(only_databases: nil) reset_column_in_all_models disable_migrations_output do - migration_context.up + migrate_databases!(only_databases: only_databases) end reset_column_in_all_models diff --git a/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb b/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb index 19b1cee44ee..9cdde13b36b 100644 --- a/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb +++ b/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb @@ -21,6 +21,8 @@ RSpec.shared_examples_for 'metrics dashboard prometheus api proxy' do end before do + stub_feature_flags(remove_monitor_metrics: false) + allow_next_instance_of(Prometheus::ProxyService, *service_params) do |proxy_service| allow(proxy_service).to receive(:execute).and_return(service_result) end @@ -106,6 +108,19 @@ RSpec.shared_examples_for 'metrics dashboard prometheus api proxy' do end end end + + context 'when metrics dashboard feature is unavailable' do + before do + stub_feature_flags(remove_monitor_metrics: true) + end + + it 'returns 404 not found' do + get :prometheus_proxy, params: prometheus_proxy_params + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_empty + end + end end context 'with inappropriate requests' do diff --git a/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb b/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb index cb8f6721d66..5b63ef10c85 100644 --- a/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb +++ b/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb @@ -17,6 +17,10 @@ RSpec.shared_examples_for 'GET #metrics_dashboard for dashboard' do |dashboard_n let(:expected_keys) { %w(dashboard status metrics_data) } let(:status_code) { :ok } + before do + stub_feature_flags(remove_monitor_metrics: false) + end + it_behaves_like 'GET #metrics_dashboard correctly formatted response' it 'returns correct dashboard' do @@ -24,4 +28,17 @@ RSpec.shared_examples_for 'GET #metrics_dashboard for dashboard' do |dashboard_n expect(json_response['dashboard']['dashboard']).to eq(dashboard_name) end + + context 'when metrics dashboard feature is unavailable' do + before do + stub_feature_flags(remove_monitor_metrics: true) + end + + it 'returns 404 not found' do + get :metrics_dashboard, params: metrics_dashboard_req_params, format: :json + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_empty + end + end end diff --git a/spec/support/shared_examples/namespaces/traversal_scope_examples.rb b/spec/support/shared_examples/namespaces/traversal_scope_examples.rb index 4afed5139d8..0c4e5ce51fc 100644 --- a/spec/support/shared_examples/namespaces/traversal_scope_examples.rb +++ b/spec/support/shared_examples/namespaces/traversal_scope_examples.rb @@ -139,29 +139,10 @@ RSpec.shared_examples 'namespace traversal scopes' do end describe '.self_and_ancestors' do - context "use_traversal_ids_ancestor_scopes feature flag is true" do - before do - stub_feature_flags(use_traversal_ids: true) - stub_feature_flags(use_traversal_ids_for_ancestor_scopes: true) - end - - it_behaves_like '.self_and_ancestors' - - it 'not make recursive queries' do - expect { described_class.where(id: [nested_group_1]).self_and_ancestors.load }.not_to make_queries_matching(/WITH RECURSIVE/) - end - end - - context "use_traversal_ids_ancestor_scopes feature flag is false" do - before do - stub_feature_flags(use_traversal_ids_for_ancestor_scopes: false) - end + it_behaves_like '.self_and_ancestors' - it_behaves_like '.self_and_ancestors' - - it 'makes recursive queries' do - expect { described_class.where(id: [nested_group_1]).self_and_ancestors.load }.to make_queries_matching(/WITH RECURSIVE/) - end + it 'not make recursive queries' do + expect { described_class.where(id: [nested_group_1]).self_and_ancestors.load }.not_to make_queries_matching(/WITH RECURSIVE/) end end @@ -197,29 +178,10 @@ RSpec.shared_examples 'namespace traversal scopes' do end describe '.self_and_ancestor_ids' do - context "use_traversal_ids_ancestor_scopes feature flag is true" do - before do - stub_feature_flags(use_traversal_ids: true) - stub_feature_flags(use_traversal_ids_for_ancestor_scopes: true) - end - - it_behaves_like '.self_and_ancestor_ids' - - it 'makes recursive queries' do - expect { described_class.where(id: [nested_group_1]).self_and_ancestor_ids.load }.not_to make_queries_matching(/WITH RECURSIVE/) - end - end - - context "use_traversal_ids_ancestor_scopes feature flag is false" do - before do - stub_feature_flags(use_traversal_ids_for_ancestor_scopes: false) - end + it_behaves_like '.self_and_ancestor_ids' - it_behaves_like '.self_and_ancestor_ids' - - it 'makes recursive queries' do - expect { described_class.where(id: [nested_group_1]).self_and_ancestor_ids.load }.to make_queries_matching(/WITH RECURSIVE/) - end + it 'not make recursive queries' do + expect { described_class.where(id: [nested_group_1]).self_and_ancestor_ids.load }.not_to make_queries_matching(/WITH RECURSIVE/) end end |
