Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-17 00:11:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-17 00:11:53 +0300
commit7ea46a9866101f15734b557d812bb52d347f63fb (patch)
treec752e2f04dab642e8b3d8d026dd530a7d4c1f229 /spec
parent889bf7a0eea1f4ac7c2ec28cdfded399c0ca8fb9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/application_controller_spec.rb2
-rw-r--r--spec/controllers/sessions_controller_spec.rb10
-rw-r--r--spec/frontend/api_spec.js32
-rw-r--r--spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js71
-rw-r--r--spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js24
-rw-r--r--spec/frontend/deploy_freeze/store/actions_spec.js82
-rw-r--r--spec/frontend/deploy_freeze/store/mutations_spec.js15
-rw-r--r--spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap4
-rw-r--r--spec/frontend_integration/test_helpers/mock_server/index.js2
-rw-r--r--spec/lib/gitlab/application_context_spec.rb16
-rw-r--r--spec/lib/gitlab/metrics/background_transaction_spec.rb4
-rw-r--r--spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb2
-rw-r--r--spec/requests/api/api_spec.rb4
-rw-r--r--spec/serializers/build_artifact_entity_spec.rb29
-rw-r--r--spec/spec_helper.rb18
-rw-r--r--spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb12
-rw-r--r--spec/workers/background_migration_worker_spec.rb2
-rw-r--r--spec/workers/concerns/worker_context_spec.rb2
19 files changed, 275 insertions, 60 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 4809a07f6e9..3d34db6c2c0 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -898,7 +898,7 @@ RSpec.describe ApplicationController do
feature_category :issue_tracking
def index
- Labkit::Context.with_context do |context|
+ Gitlab::ApplicationContext.with_raw_context do |context|
render json: context.to_h
end
end
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb
index c31ba6fe156..5bee7698c3f 100644
--- a/spec/controllers/sessions_controller_spec.rb
+++ b/spec/controllers/sessions_controller_spec.rb
@@ -524,7 +524,7 @@ RSpec.describe SessionsController do
it 'sets the username and caller_id in the context' do
expect(controller).to receive(:destroy).and_wrap_original do |m, *args|
- expect(Labkit::Context.current.to_h)
+ expect(Gitlab::ApplicationContext.current)
.to include('meta.user' => user.username,
'meta.caller_id' => 'SessionsController#destroy')
@@ -538,9 +538,9 @@ RSpec.describe SessionsController do
context 'when not signed in' do
it 'sets the caller_id in the context' do
expect(controller).to receive(:new).and_wrap_original do |m, *args|
- expect(Labkit::Context.current.to_h)
+ expect(Gitlab::ApplicationContext.current)
.to include('meta.caller_id' => 'SessionsController#new')
- expect(Labkit::Context.current.to_h)
+ expect(Gitlab::ApplicationContext.current)
.not_to include('meta.user')
m.call(*args)
@@ -557,9 +557,9 @@ RSpec.describe SessionsController do
it 'sets the caller_id in the context' do
allow_any_instance_of(User).to receive(:lock_access!).and_wrap_original do |m, *args|
- expect(Labkit::Context.current.to_h)
+ expect(Gitlab::ApplicationContext.current)
.to include('meta.caller_id' => 'SessionsController#create')
- expect(Labkit::Context.current.to_h)
+ expect(Gitlab::ApplicationContext.current)
.not_to include('meta.user')
m.call(*args)
diff --git a/spec/frontend/api_spec.js b/spec/frontend/api_spec.js
index d6e1b170dd3..f875e3bdb07 100644
--- a/spec/frontend/api_spec.js
+++ b/spec/frontend/api_spec.js
@@ -1382,6 +1382,38 @@ describe('Api', () => {
});
});
+ describe('updateFreezePeriod', () => {
+ const options = {
+ id: 10,
+ freeze_start: '* * * * *',
+ freeze_end: '* * * * *',
+ cron_timezone: 'America/Juneau',
+ created_at: '2020-07-11T07:04:50.153Z',
+ updated_at: '2020-07-11T07:04:50.153Z',
+ };
+ const projectId = 8;
+ const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/freeze_periods/${options.id}`;
+
+ const expectedResult = {
+ id: 10,
+ freeze_start: '* * * * *',
+ freeze_end: '* * * * *',
+ cron_timezone: 'America/Juneau',
+ created_at: '2020-07-11T07:04:50.153Z',
+ updated_at: '2020-07-11T07:04:50.153Z',
+ };
+
+ describe('when the freeze period is successfully updated', () => {
+ it('resolves the Promise', () => {
+ mock.onPut(expectedUrl, options).replyOnce(httpStatus.OK, expectedResult);
+
+ return Api.updateFreezePeriod(projectId, options).then(({ data }) => {
+ expect(data).toStrictEqual(expectedResult);
+ });
+ });
+ });
+ });
+
describe('createPipeline', () => {
it('creates new pipeline', () => {
const redirectUrl = 'ci-project/-/pipelines/95';
diff --git a/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js b/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js
index d8ce184940a..7c46c280d46 100644
--- a/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js
+++ b/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js
@@ -1,13 +1,16 @@
import { GlButton, GlModal } from '@gitlab/ui';
-import { createLocalVue, shallowMount } from '@vue/test-utils';
+import { shallowMount } from '@vue/test-utils';
+import Vue from 'vue';
import Vuex from 'vuex';
+import Api from '~/api';
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
import createStore from '~/deploy_freeze/store';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
-const localVue = createLocalVue();
-localVue.use(Vuex);
+jest.mock('~/api');
+
+Vue.use(Vuex);
describe('Deploy freeze modal', () => {
let wrapper;
@@ -23,18 +26,19 @@ describe('Deploy freeze modal', () => {
stubs: {
GlModal,
},
- localVue,
store,
});
});
- const findModal = () => wrapper.find(GlModal);
- const addDeployFreezeButton = () => findModal().findAll(GlButton).at(1);
+ const findModal = () => wrapper.findComponent(GlModal);
+ const submitDeployFreezeButton = () => findModal().findAllComponents(GlButton).at(1);
- const setInput = (freezeStartCron, freezeEndCron, selectedTimezone) => {
+ const setInput = (freezeStartCron, freezeEndCron, selectedTimezone, id = '') => {
store.state.freezeStartCron = freezeStartCron;
store.state.freezeEndCron = freezeEndCron;
store.state.selectedTimezone = selectedTimezone;
+ store.state.selectedTimezoneIdentifier = selectedTimezone;
+ store.state.selectedId = id;
wrapper.find('#deploy-freeze-start').trigger('input');
wrapper.find('#deploy-freeze-end').trigger('input');
@@ -48,18 +52,36 @@ describe('Deploy freeze modal', () => {
describe('Basic interactions', () => {
it('button is disabled when freeze period is invalid', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeTruthy();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeTruthy();
});
});
describe('Adding a new deploy freeze', () => {
+ const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
+
beforeEach(() => {
- const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
setInput(freeze_start, freeze_end, cron_timezone);
});
it('button is enabled when valid freeze period settings are present', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeUndefined();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeUndefined();
+ });
+
+ it('should display Add deploy freeze', () => {
+ expect(findModal().props('title')).toBe('Add deploy freeze');
+ expect(submitDeployFreezeButton().text()).toBe('Add deploy freeze');
+ });
+
+ it('should call the add deploy freze API', () => {
+ Api.createFreezePeriod.mockResolvedValue();
+ findModal().vm.$emit('primary');
+
+ expect(Api.createFreezePeriod).toHaveBeenCalledTimes(1);
+ expect(Api.createFreezePeriod).toHaveBeenCalledWith(store.state.projectId, {
+ freeze_start,
+ freeze_end,
+ cron_timezone,
+ });
});
});
@@ -70,7 +92,7 @@ describe('Deploy freeze modal', () => {
});
it('disables the add deploy freeze button', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeTruthy();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeTruthy();
});
});
@@ -81,7 +103,32 @@ describe('Deploy freeze modal', () => {
});
it('does not disable the submit button', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeFalsy();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeFalsy();
+ });
+ });
+ });
+
+ describe('Editing an existing deploy freeze', () => {
+ const { freeze_start, freeze_end, cron_timezone, id } = freezePeriodsFixture[0];
+ beforeEach(() => {
+ setInput(freeze_start, freeze_end, cron_timezone, id);
+ });
+
+ it('should display Edit deploy freeze', () => {
+ expect(findModal().props('title')).toBe('Edit deploy freeze');
+ expect(submitDeployFreezeButton().text()).toBe('Save deploy freeze');
+ });
+
+ it('should call the update deploy freze API', () => {
+ Api.updateFreezePeriod.mockResolvedValue();
+ findModal().vm.$emit('primary');
+
+ expect(Api.updateFreezePeriod).toHaveBeenCalledTimes(1);
+ expect(Api.updateFreezePeriod).toHaveBeenCalledWith(store.state.projectId, {
+ id,
+ freeze_start,
+ freeze_end,
+ cron_timezone,
});
});
});
diff --git a/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js b/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js
index e4ee1b9ad26..168ddcfeacc 100644
--- a/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js
+++ b/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js
@@ -2,6 +2,7 @@ import { createLocalVue, mount } from '@vue/test-utils';
import Vuex from 'vuex';
import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue';
import createStore from '~/deploy_freeze/store';
+import { RECEIVE_FREEZE_PERIODS_SUCCESS } from '~/deploy_freeze/store/mutation_types';
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue();
@@ -26,6 +27,7 @@ describe('Deploy freeze table', () => {
const findEmptyFreezePeriods = () => wrapper.find('[data-testid="empty-freeze-periods"]');
const findAddDeployFreezeButton = () => wrapper.find('[data-testid="add-deploy-freeze"]');
+ const findEditDeployFreezeButton = () => wrapper.find('[data-testid="edit-deploy-freeze"]');
const findDeployFreezeTable = () => wrapper.find('[data-testid="deploy-freeze-table"]');
beforeEach(() => {
@@ -45,17 +47,31 @@ describe('Deploy freeze table', () => {
it('displays empty', () => {
expect(findEmptyFreezePeriods().exists()).toBe(true);
expect(findEmptyFreezePeriods().text()).toBe(
- 'No deploy freezes exist for this project. To add one, click Add deploy freeze',
+ 'No deploy freezes exist for this project. To add one, select Add deploy freeze',
);
});
- it('displays data', () => {
- store.state.freezePeriods = freezePeriodsFixture;
+ describe('with data', () => {
+ beforeEach(async () => {
+ store.commit(RECEIVE_FREEZE_PERIODS_SUCCESS, freezePeriodsFixture);
+ await wrapper.vm.$nextTick();
+ });
- return wrapper.vm.$nextTick(() => {
+ it('displays data', () => {
const tableRows = findDeployFreezeTable().findAll('tbody tr');
expect(tableRows.length).toBe(freezePeriodsFixture.length);
expect(findEmptyFreezePeriods().exists()).toBe(false);
+ expect(findEditDeployFreezeButton().exists()).toBe(true);
+ });
+
+ it('allows user to edit deploy freeze', async () => {
+ findEditDeployFreezeButton().trigger('click');
+ await wrapper.vm.$nextTick();
+
+ expect(store.dispatch).toHaveBeenCalledWith(
+ 'setFreezePeriod',
+ store.state.freezePeriods[0],
+ );
});
});
});
diff --git a/spec/frontend/deploy_freeze/store/actions_spec.js b/spec/frontend/deploy_freeze/store/actions_spec.js
index f4d9802e39a..9c784f3c5a2 100644
--- a/spec/frontend/deploy_freeze/store/actions_spec.js
+++ b/spec/frontend/deploy_freeze/store/actions_spec.js
@@ -23,12 +23,46 @@ describe('deploy freeze store actions', () => {
});
Api.freezePeriods.mockResolvedValue({ data: freezePeriodsFixture });
Api.createFreezePeriod.mockResolvedValue();
+ Api.updateFreezePeriod.mockResolvedValue();
});
afterEach(() => {
mock.restore();
});
+ describe('setSelectedFreezePeriod', () => {
+ it('commits SET_SELECTED_TIMEZONE mutation', () => {
+ testAction(
+ actions.setFreezePeriod,
+ {
+ id: 3,
+ cronTimezone: 'UTC',
+ freezeStart: 'start',
+ freezeEnd: 'end',
+ },
+ {},
+ [
+ {
+ payload: 3,
+ type: types.SET_SELECTED_ID,
+ },
+ {
+ payload: 'UTC',
+ type: types.SET_SELECTED_TIMEZONE,
+ },
+ {
+ payload: 'start',
+ type: types.SET_FREEZE_START_CRON,
+ },
+ {
+ payload: 'end',
+ type: types.SET_FREEZE_END_CRON,
+ },
+ ],
+ );
+ });
+ });
+
describe('setSelectedTimezone', () => {
it('commits SET_SELECTED_TIMEZONE mutation', () => {
testAction(actions.setSelectedTimezone, {}, {}, [
@@ -68,10 +102,16 @@ describe('deploy freeze store actions', () => {
state,
[{ type: 'RESET_MODAL' }],
[
- { type: 'requestAddFreezePeriod' },
- { type: 'receiveAddFreezePeriodSuccess' },
+ { type: 'requestFreezePeriod' },
+ { type: 'receiveFreezePeriodSuccess' },
{ type: 'fetchFreezePeriods' },
],
+ () =>
+ expect(Api.createFreezePeriod).toHaveBeenCalledWith(state.projectId, {
+ freeze_start: state.freezeStartCron,
+ freeze_end: state.freezeEndCron,
+ cron_timezone: state.selectedTimezoneIdentifier,
+ }),
);
});
@@ -83,7 +123,43 @@ describe('deploy freeze store actions', () => {
{},
state,
[],
- [{ type: 'requestAddFreezePeriod' }, { type: 'receiveAddFreezePeriodError' }],
+ [{ type: 'requestFreezePeriod' }, { type: 'receiveFreezePeriodError' }],
+ () => expect(createFlash).toHaveBeenCalled(),
+ );
+ });
+ });
+
+ describe('updateFreezePeriod', () => {
+ it('dispatch correct actions on updating a freeze period', () => {
+ testAction(
+ actions.updateFreezePeriod,
+ {},
+ state,
+ [{ type: 'RESET_MODAL' }],
+ [
+ { type: 'requestFreezePeriod' },
+ { type: 'receiveFreezePeriodSuccess' },
+ { type: 'fetchFreezePeriods' },
+ ],
+ () =>
+ expect(Api.updateFreezePeriod).toHaveBeenCalledWith(state.projectId, {
+ id: state.selectedId,
+ freeze_start: state.freezeStartCron,
+ freeze_end: state.freezeEndCron,
+ cron_timezone: state.selectedTimezoneIdentifier,
+ }),
+ );
+ });
+
+ it('should show flash error and set error in state on add failure', () => {
+ Api.updateFreezePeriod.mockRejectedValue();
+
+ testAction(
+ actions.updateFreezePeriod,
+ {},
+ state,
+ [],
+ [{ type: 'requestFreezePeriod' }, { type: 'receiveFreezePeriodError' }],
() => expect(createFlash).toHaveBeenCalled(),
);
});
diff --git a/spec/frontend/deploy_freeze/store/mutations_spec.js b/spec/frontend/deploy_freeze/store/mutations_spec.js
index 54cbdfcb64c..ce75e3b89c3 100644
--- a/spec/frontend/deploy_freeze/store/mutations_spec.js
+++ b/spec/frontend/deploy_freeze/store/mutations_spec.js
@@ -33,7 +33,10 @@ describe('Deploy freeze mutations', () => {
const expectedFreezePeriods = freezePeriodsFixture.map((freezePeriod, index) => ({
...convertObjectPropsToCamelCase(freezePeriod),
- cronTimezone: timezoneNames[index],
+ cronTimezone: {
+ formattedTimezone: timezoneNames[index],
+ identifier: freezePeriod.cronTimezone,
+ },
}));
expect(stateCopy.freezePeriods).toMatchObject(expectedFreezePeriods);
@@ -62,11 +65,19 @@ describe('Deploy freeze mutations', () => {
});
});
- describe('SET_FREEZE_ENDT_CRON', () => {
+ describe('SET_FREEZE_END_CRON', () => {
it('should set freezeEndCron', () => {
mutations[types.SET_FREEZE_END_CRON](stateCopy, '5 0 * 8 *');
expect(stateCopy.freezeEndCron).toBe('5 0 * 8 *');
});
});
+
+ describe('SET_SELECTED_ID', () => {
+ it('should set selectedId', () => {
+ mutations[types.SET_SELECTED_ID](stateCopy, 5);
+
+ expect(stateCopy.selectedId).toBe(5);
+ });
+ });
});
diff --git a/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap b/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap
index 4398d568501..07f90a12f0f 100644
--- a/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap
+++ b/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap
@@ -9,7 +9,9 @@ exports[`IncidentsSettingTabs should render the component 1`] = `
<div
class="settings-header"
>
- <h4>
+ <h4
+ class="settings-title js-settings-toggle js-settings-toggle-trigger-only"
+ >
Incidents
diff --git a/spec/frontend_integration/test_helpers/mock_server/index.js b/spec/frontend_integration/test_helpers/mock_server/index.js
index 20cb441daa7..486c9452dbd 100644
--- a/spec/frontend_integration/test_helpers/mock_server/index.js
+++ b/spec/frontend_integration/test_helpers/mock_server/index.js
@@ -1,4 +1,5 @@
import { Server, Model, RestSerializer } from 'miragejs';
+import setupRoutes from 'ee_else_ce_test_helpers/mock_server/routes';
import {
getProject,
getEmptyProject,
@@ -11,7 +12,6 @@ import {
getBlobImage,
getBlobZip,
} from 'test_helpers/fixtures';
-import setupRoutes from './routes';
export const createMockServerOptions = () => ({
models: {
diff --git a/spec/lib/gitlab/application_context_spec.rb b/spec/lib/gitlab/application_context_spec.rb
index 0fbbc67ef6a..c4fe2ebaba9 100644
--- a/spec/lib/gitlab/application_context_spec.rb
+++ b/spec/lib/gitlab/application_context_spec.rb
@@ -27,6 +27,20 @@ RSpec.describe Gitlab::ApplicationContext do
end
end
+ describe '.with_raw_context' do
+ it 'yields the block' do
+ expect { |b| described_class.with_raw_context({}, &b) }.to yield_control
+ end
+
+ it 'passes the attributes unaltered on to labkit' do
+ attrs = { foo: :bar }
+
+ expect(Labkit::Context).to receive(:with_context).with(attrs)
+
+ described_class.with_raw_context(attrs) {}
+ end
+ end
+
describe '.push' do
it 'passes the expected context on to labkit' do
fake_proc = duck_type(:call)
@@ -138,7 +152,7 @@ RSpec.describe Gitlab::ApplicationContext do
it 'does not cause queries' do
context = described_class.new(project: create(:project), namespace: create(:group, :nested), user: create(:user))
- expect { context.use { Labkit::Context.current.to_h } }.not_to exceed_query_limit(0)
+ expect { context.use { Gitlab::ApplicationContext.current } }.not_to exceed_query_limit(0)
end
end
end
diff --git a/spec/lib/gitlab/metrics/background_transaction_spec.rb b/spec/lib/gitlab/metrics/background_transaction_spec.rb
index b31a2f7549a..15e52f7b6c8 100644
--- a/spec/lib/gitlab/metrics/background_transaction_spec.rb
+++ b/spec/lib/gitlab/metrics/background_transaction_spec.rb
@@ -30,7 +30,7 @@ RSpec.describe Gitlab::Metrics::BackgroundTransaction do
describe '#labels' do
it 'provides labels with endpoint_id and feature_category' do
- Labkit::Context.with_context(feature_category: 'projects', caller_id: 'TestWorker') do
+ Gitlab::ApplicationContext.with_raw_context(feature_category: 'projects', caller_id: 'TestWorker') do
expect(transaction.labels).to eq({ endpoint_id: 'TestWorker', feature_category: 'projects' })
end
end
@@ -41,7 +41,7 @@ RSpec.describe Gitlab::Metrics::BackgroundTransaction do
value = 1
expect(prometheus_metric).to receive(metric_method).with({ endpoint_id: 'TestWorker', feature_category: 'projects' }, value)
- Labkit::Context.with_context(feature_category: 'projects', caller_id: 'TestWorker') do
+ Gitlab::ApplicationContext.with_raw_context(feature_category: 'projects', caller_id: 'TestWorker') do
transaction.send(metric_method, :test_metric, value)
end
end
diff --git a/spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb b/spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb
index ca473462d2e..f736a7db774 100644
--- a/spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb
+++ b/spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Server do
worker_context user: nil
def perform(identifier, *args)
- self.class.contexts.merge!(identifier => Labkit::Context.current.to_h)
+ self.class.contexts.merge!(identifier => Gitlab::ApplicationContext.current)
end
end
end
diff --git a/spec/requests/api/api_spec.rb b/spec/requests/api/api_spec.rb
index 522030652bd..7e670724c11 100644
--- a/spec/requests/api/api_spec.rb
+++ b/spec/requests/api/api_spec.rb
@@ -105,7 +105,7 @@ RSpec.describe API::API do
it 'logs all application context fields' do
allow_any_instance_of(Gitlab::GrapeLogging::Loggers::ContextLogger).to receive(:parameters) do
- Labkit::Context.current.to_h.tap do |log_context|
+ Gitlab::ApplicationContext.current.tap do |log_context|
expect(log_context).to match('correlation_id' => an_instance_of(String),
'meta.caller_id' => '/api/:version/projects/:id/issues',
'meta.remote_ip' => an_instance_of(String),
@@ -122,7 +122,7 @@ RSpec.describe API::API do
it 'skips fields that do not apply' do
allow_any_instance_of(Gitlab::GrapeLogging::Loggers::ContextLogger).to receive(:parameters) do
- Labkit::Context.current.to_h.tap do |log_context|
+ Gitlab::ApplicationContext.current.tap do |log_context|
expect(log_context).to match('correlation_id' => an_instance_of(String),
'meta.caller_id' => '/api/:version/users',
'meta.remote_ip' => an_instance_of(String),
diff --git a/spec/serializers/build_artifact_entity_spec.rb b/spec/serializers/build_artifact_entity_spec.rb
index 02c172d723f..87c1874ec41 100644
--- a/spec/serializers/build_artifact_entity_spec.rb
+++ b/spec/serializers/build_artifact_entity_spec.rb
@@ -21,15 +21,30 @@ RSpec.describe BuildArtifactEntity do
expect(subject).to include(:expired, :expire_at)
end
- it 'contains paths to the artifacts' do
- expect(subject[:path])
- .to include "jobs/#{job.id}/artifacts/download?file_type=codequality"
+ it 'exposes the artifact download path' do
+ expect(subject[:path]).to include "jobs/#{job.id}/artifacts/download?file_type=codequality"
+ end
+
+ context 'with remove_duplicate_artifact_exposure_paths enabled' do
+ before do
+ stub_feature_flags(remove_duplicate_artifact_exposure_paths: true)
+ end
+
+ it 'has no keep or browse path' do
+ expect(subject).not_to include(:keep_path)
+ expect(subject).not_to include(:browse_path)
+ end
+ end
- expect(subject[:keep_path])
- .to include "jobs/#{job.id}/artifacts/keep"
+ context 'with remove_duplicate_artifact_exposure_paths disabled' do
+ before do
+ stub_feature_flags(remove_duplicate_artifact_exposure_paths: false)
+ end
- expect(subject[:browse_path])
- .to include "jobs/#{job.id}/artifacts/browse"
+ it 'has keep and browse paths' do
+ expect(subject[:keep_path]).to be_present
+ expect(subject[:browse_path]).to be_present
+ end
end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b15d91b41e4..5f1513b1247 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -333,10 +333,20 @@ RSpec.configure do |config|
RequestStore.clear!
end
- config.around do |example|
- # Wrap each example in it's own context to make sure the contexts don't
- # leak
- Labkit::Context.with_context { example.run }
+ if ENV['SKIP_RSPEC_CONTEXT_WRAPPING']
+ config.around(:example, :context_aware) do |example|
+ # Wrap each example in it's own context to make sure the contexts don't
+ # leak
+ Gitlab::ApplicationContext.with_raw_context { example.run }
+ end
+ else
+ config.around do |example|
+ if [:controller, :request, :feature].include?(example.metadata[:type]) || example.metadata[:context_aware]
+ Gitlab::ApplicationContext.with_raw_context { example.run }
+ else
+ example.run
+ end
+ end
end
config.around do |example|
diff --git a/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb b/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb
index bdb0316bf5a..c775ca182e6 100644
--- a/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb
+++ b/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
RSpec.shared_examples 'API::CI::Runner application context metadata' do |api_route|
- it 'contains correct context metadata' do
+ it 'contains correct context metadata', :context_aware do
# Avoids popping the context from the thread so we can
# check its content after the request.
allow(Labkit::Context).to receive(:pop)
send_request
- Labkit::Context.with_context do |context|
+ Gitlab::ApplicationContext.with_raw_context do |context|
expected_context = {
'meta.caller_id' => api_route,
'meta.user' => job.user.username,
diff --git a/spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb b/spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
index 4a71b696d57..57e28e6df57 100644
--- a/spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
+++ b/spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
@@ -1,21 +1,13 @@
# frozen_string_literal: true
RSpec.shared_examples 'storing arguments in the application context' do
- around do |example|
- Labkit::Context.with_context { example.run }
- end
-
- it 'places the expected params in the application context' do
+ it 'places the expected params in the application context', :context_aware do
# Stub the clearing of the context so we can validate it later
- # The `around` block above makes sure we do clean it up later
allow(Labkit::Context).to receive(:pop)
subject
- Labkit::Context.with_context do |context|
- expect(context.to_h)
- .to include(log_hash(expected_params))
- end
+ expect(Gitlab::ApplicationContext.current).to include(log_hash(expected_params))
end
def log_hash(hash)
diff --git a/spec/workers/background_migration_worker_spec.rb b/spec/workers/background_migration_worker_spec.rb
index 8094efcaf04..4575c270042 100644
--- a/spec/workers/background_migration_worker_spec.rb
+++ b/spec/workers/background_migration_worker_spec.rb
@@ -101,7 +101,7 @@ RSpec.describe BackgroundMigrationWorker, :clean_gitlab_redis_shared_state do
it 'sets the class that will be executed as the caller_id' do
expect(Gitlab::BackgroundMigration).to receive(:perform) do
- expect(Labkit::Context.current.to_h).to include('meta.caller_id' => 'Foo')
+ expect(Gitlab::ApplicationContext.current).to include('meta.caller_id' => 'Foo')
end
worker.perform('Foo', [10, 20])
diff --git a/spec/workers/concerns/worker_context_spec.rb b/spec/workers/concerns/worker_context_spec.rb
index 3de37b99aba..ebdb752d900 100644
--- a/spec/workers/concerns/worker_context_spec.rb
+++ b/spec/workers/concerns/worker_context_spec.rb
@@ -103,7 +103,7 @@ RSpec.describe WorkerContext do
describe '#with_context' do
it 'allows modifying context when the job is running' do
worker.new.with_context(user: build_stubbed(:user, username: 'jane-doe')) do
- expect(Labkit::Context.current.to_h).to include('meta.user' => 'jane-doe')
+ expect(Gitlab::ApplicationContext.current).to include('meta.user' => 'jane-doe')
end
end