Skip to content
Snippets Groups Projects
Commit 2ed36892 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent f1a57558
No related branches found
No related tags found
No related merge requests found
Showing
with 375 additions and 27 deletions
import { createLocalVue, shallowMount } from '@vue/test-utils';
import GlFeatureFlags from '~/vue_shared/gl_feature_flags_plugin';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
const localVue = createLocalVue();
describe('GitLab Feature Flags Plugin', () => {
beforeEach(() => {
window.gon = {
features: {
aFeature: true,
bFeature: false,
},
};
localVue.use(GlFeatureFlags);
});
it('should provide glFeatures to components', () => {
const component = {
template: `<span></span>`,
inject: ['glFeatures'],
};
const wrapper = shallowMount(component, { localVue });
expect(wrapper.vm.glFeatures).toEqual({
aFeature: true,
bFeature: false,
});
});
it('should integrate with the glFeatureMixin', () => {
const component = {
template: `<span></span>`,
mixins: [glFeatureFlagsMixin()],
};
const wrapper = shallowMount(component, { localVue });
expect(wrapper.vm.glFeatures).toEqual({
aFeature: true,
bFeature: false,
});
});
});
import { createLocalVue, shallowMount } from '@vue/test-utils';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
const localVue = createLocalVue();
describe('GitLab Feature Flags Mixin', () => {
let wrapper;
beforeEach(() => {
const gon = {
features: {
aFeature: true,
bFeature: false,
},
};
const component = {
template: `<span></span>`,
mixins: [glFeatureFlagsMixin()],
};
wrapper = shallowMount(component, {
localVue,
provide: {
glFeatures: { ...(gon.features || {}) },
},
});
});
it('should provide glFeatures to components', () => {
expect(wrapper.vm.glFeatures).toEqual({
aFeature: true,
bFeature: false,
});
});
});
Loading
Loading
@@ -243,4 +243,32 @@ describe IssuablesHelper do
end
end
end
describe '#assignee_sidebar_data' do
let(:user) { create(:user) }
let(:merge_request) { nil }
subject { helper.assignee_sidebar_data(user, merge_request: merge_request) }
it 'returns hash of assignee data' do
is_expected.to eql({
avatar_url: user.avatar_url,
name: user.name,
username: user.username
})
end
context 'with merge_request' do
let(:merge_request) { build_stubbed(:merge_request) }
where(can_merge: [true, false])
with_them do
before do
allow(merge_request).to receive(:can_be_merged_by?).and_return(can_merge)
end
it { is_expected.to include({ can_merge: can_merge })}
end
end
end
end
Loading
Loading
@@ -4,6 +4,7 @@ import { createStore } from '~/create_cluster/gke_cluster/store';
import { SET_PROJECTS } from '~/create_cluster/gke_cluster/store/mutation_types';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { emptyProjectMock, selectedProjectMock } from '../mock_data';
import { gapi } from '../helpers';
 
const componentConfig = {
docsUrl: 'https://console.cloud.google.com/home/dashboard',
Loading
Loading
@@ -32,6 +33,16 @@ describe('GkeProjectIdDropdown', () => {
let vm;
let store;
 
let originalGapi;
beforeAll(() => {
originalGapi = window.gapi;
window.gapi = gapi();
});
afterAll(() => {
window.gapi = originalGapi;
});
beforeEach(() => {
store = createStore();
vm = createComponent(store);
Loading
Loading
Loading
Loading
@@ -64,7 +64,15 @@ describe('GCP Cluster Dropdown Store Actions', () => {
});
 
describe('async fetch methods', () => {
window.gapi = gapi();
let originalGapi;
beforeAll(() => {
originalGapi = window.gapi;
window.gapi = gapi();
});
afterAll(() => {
window.gapi = originalGapi;
});
 
describe('fetchProjects', () => {
it('fetches projects from Google API', done => {
Loading
Loading
Loading
Loading
@@ -527,7 +527,6 @@ describe('Dashboard', () => {
 
component.$store.dispatch('monitoringDashboard/setFeatureFlags', {
prometheusEndpoint: false,
multipleDashboardsEnabled: true,
});
 
component.$store.commit(
Loading
Loading
Loading
Loading
@@ -240,8 +240,6 @@ describe('Monitoring store actions', () => {
const response = metricsDashboardResponse;
 
response.all_dashboards = dashboardGitResponse;
state.multipleDashboardsEnabled = true;
receiveMetricsDashboardSuccess({ state, commit, dispatch }, { response, params });
 
expect(commit).toHaveBeenCalledWith(types.SET_ALL_DASHBOARDS, dashboardGitResponse);
Loading
Loading
Loading
Loading
@@ -47,7 +47,7 @@ describe('Wip', () => {
it('should make a request to service and handle response', done => {
const vm = createComponent();
 
spyOn(window, 'Flash').and.returnValue(true);
const flashSpy = spyOnDependency(WorkInProgress, 'createFlash').and.returnValue(true);
spyOn(eventHub, '$emit');
spyOn(vm.service, 'removeWIP').and.returnValue(
new Promise(resolve => {
Loading
Loading
@@ -61,10 +61,7 @@ describe('Wip', () => {
setTimeout(() => {
expect(vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('UpdateWidgetData', mrObj);
expect(window.Flash).toHaveBeenCalledWith(
'The merge request can now be merged.',
'notice',
);
expect(flashSpy).toHaveBeenCalledWith('The merge request can now be merged.', 'notice');
done();
}, 333);
});
Loading
Loading
# frozen_string_literal: true
require 'fast_spec_helper'
describe Gitlab::Ci::Config::External::Context do
let(:project) { double('Project') }
let(:user) { double('User') }
let(:sha) { '12345' }
let(:attributes) { { project: project, user: user, sha: sha } }
subject(:subject) { described_class.new(**attributes) }
describe 'attributes' do
context 'with values' do
it { is_expected.to have_attributes(**attributes) }
it { expect(subject.expandset).to eq(Set.new) }
it { expect(subject.execution_deadline).to eq(0) }
end
context 'without values' do
let(:attributes) { { project: nil, user: nil, sha: nil } }
it { is_expected.to have_attributes(**attributes) }
it { expect(subject.expandset).to eq(Set.new) }
it { expect(subject.execution_deadline).to eq(0) }
end
end
describe '#set_deadline' do
let(:stubbed_time) { 1 }
before do
allow(subject).to receive(:current_monotonic_time).and_return(stubbed_time)
end
context 'with a float value' do
let(:timeout_seconds) { 10.5.seconds }
it 'updates execution_deadline' do
expect { subject.set_deadline(timeout_seconds) }
.to change { subject.execution_deadline }
.to(timeout_seconds + stubbed_time)
end
end
context 'with nil as a value' do
let(:timeout_seconds) {}
it 'updates execution_deadline' do
expect { subject.set_deadline(timeout_seconds) }
.to change { subject.execution_deadline }
.to(stubbed_time)
end
end
end
describe '#check_execution_time!' do
before do
allow(subject).to receive(:current_monotonic_time).and_return(stubbed_time)
allow(subject).to receive(:execution_deadline).and_return(stubbed_deadline)
end
context 'when execution is expired' do
let(:stubbed_time) { 2 }
let(:stubbed_deadline) { 1 }
it 'raises an error' do
expect { subject.check_execution_time! }
.to raise_error(described_class::TimeoutError)
end
end
context 'when execution is not expired' do
let(:stubbed_time) { 1 }
let(:stubbed_deadline) { 2 }
it 'does not raises any errors' do
expect { subject.check_execution_time! }.not_to raise_error
end
end
context 'without setting a deadline' do
let(:stubbed_time) { 2 }
let(:stubbed_deadline) { 1 }
before do
allow(subject).to receive(:execution_deadline).and_call_original
end
it 'does not raises any errors' do
expect { subject.check_execution_time! }.not_to raise_error
end
end
end
describe '#mutate' do
shared_examples 'a mutated context' do
let(:mutated) { subject.mutate(new_attributes) }
before do
subject.expandset << :a_file
subject.set_deadline(15.seconds)
end
it { expect(mutated).not_to eq(subject) }
it { expect(mutated).to be_a(described_class) }
it { expect(mutated).to have_attributes(new_attributes) }
it { expect(mutated.expandset).to eq(subject.expandset) }
it { expect(mutated.execution_deadline).to eq(mutated.execution_deadline) }
end
context 'with attributes' do
let(:new_attributes) { { project: double, user: double, sha: '56789' } }
it_behaves_like 'a mutated context'
end
context 'without attributes' do
let(:new_attributes) { {} }
it_behaves_like 'a mutated context'
end
end
describe '#sentry_payload' do
it { expect(subject.sentry_payload).to match(a_hash_including(:project, :user)) }
end
end
# frozen_string_literal: true
 
require 'fast_spec_helper'
require 'spec_helper'
 
describe Gitlab::Ci::Config::External::File::Base do
let(:context) { described_class::Context.new(nil, 'HEAD', nil, Set.new) }
let(:context_params) { { sha: 'HEAD' } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
 
let(:test_class) do
Class.new(described_class) do
def initialize(params, context = {})
def initialize(params, context)
@location = params
 
super
Loading
Loading
@@ -20,6 +21,9 @@ describe Gitlab::Ci::Config::External::File::Base do
before do
allow_any_instance_of(test_class)
.to receive(:content).and_return('key: value')
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
 
describe '#matching?' do
Loading
Loading
Loading
Loading
@@ -7,10 +7,17 @@ describe Gitlab::Ci::Config::External::File::Local do
set(:user) { create(:user) }
 
let(:sha) { '12345' }
let(:context) { described_class::Context.new(project, sha, user, Set.new) }
let(:context_params) { { project: project, sha: sha, user: user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:params) { { local: location } }
let(:local_file) { described_class.new(params, context) }
 
before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
describe '#matching?' do
context 'when a local is specified' do
let(:params) { { local: 'file' } }
Loading
Loading
@@ -109,7 +116,7 @@ describe Gitlab::Ci::Config::External::File::Local do
describe '#expand_context' do
let(:location) { 'location.yml' }
 
subject { local_file.send(:expand_context) }
subject { local_file.send(:expand_context_attrs) }
 
it 'inherits project, user and sha' do
is_expected.to include(user: user, project: project, sha: sha)
Loading
Loading
Loading
Loading
@@ -8,11 +8,15 @@ describe Gitlab::Ci::Config::External::File::Project do
set(:user) { create(:user) }
 
let(:context_user) { user }
let(:context) { described_class::Context.new(context_project, '12345', context_user, Set.new) }
let(:context_params) { { project: context_project, sha: '12345', user: context_user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:project_file) { described_class.new(params, context) }
 
before do
project.add_developer(user)
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
 
describe '#matching?' do
Loading
Loading
@@ -145,7 +149,7 @@ describe Gitlab::Ci::Config::External::File::Project do
describe '#expand_context' do
let(:params) { { file: 'file.yml', project: project.full_path, ref: 'master' } }
 
subject { project_file.send(:expand_context) }
subject { project_file.send(:expand_context_attrs) }
 
it 'inherits user, and target project and sha' do
is_expected.to include(user: user, project: project, sha: project.commit('master').id)
Loading
Loading
Loading
Loading
@@ -5,7 +5,8 @@ require 'spec_helper'
describe Gitlab::Ci::Config::External::File::Remote do
include StubRequests
 
let(:context) { described_class::Context.new(nil, '12345', nil, Set.new) }
let(:context_params) { { sha: '12345' } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:params) { { remote: location } }
let(:remote_file) { described_class.new(params, context) }
let(:location) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' }
Loading
Loading
@@ -19,6 +20,11 @@ describe Gitlab::Ci::Config::External::File::Remote do
HEREDOC
end
 
before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
describe '#matching?' do
context 'when a remote is specified' do
let(:params) { { remote: 'http://remote' } }
Loading
Loading
@@ -187,10 +193,10 @@ describe Gitlab::Ci::Config::External::File::Remote do
describe '#expand_context' do
let(:params) { { remote: 'http://remote' } }
 
subject { remote_file.send(:expand_context) }
subject { remote_file.send(:expand_context_attrs) }
 
it 'drops all parameters' do
is_expected.to include(user: nil, project: nil, sha: nil)
is_expected.to be_empty
end
end
end
Loading
Loading
@@ -6,12 +6,18 @@ describe Gitlab::Ci::Config::External::File::Template do
set(:project) { create(:project) }
set(:user) { create(:user) }
 
let(:context) { described_class::Context.new(project, '12345', user, Set.new) }
let(:context_params) { { project: project, sha: '12345', user: user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:template) { 'Auto-DevOps.gitlab-ci.yml' }
let(:params) { { template: template } }
 
let(:template_file) { described_class.new(params, context) }
 
before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
describe '#matching?' do
context 'when a template is specified' do
let(:params) { { template: 'some-template' } }
Loading
Loading
@@ -97,10 +103,10 @@ describe Gitlab::Ci::Config::External::File::Template do
describe '#expand_context' do
let(:location) { 'location.yml' }
 
subject { template_file.send(:expand_context) }
subject { template_file.send(:expand_context_attrs) }
 
it 'drops all parameters' do
is_expected.to include(user: nil, project: nil, sha: nil)
is_expected.to be_empty
end
end
end
Loading
Loading
@@ -11,7 +11,8 @@ describe Gitlab::Ci::Config::External::Mapper do
let(:local_file) { '/lib/gitlab/ci/templates/non-existent-file.yml' }
let(:remote_url) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' }
let(:template_file) { 'Auto-DevOps.gitlab-ci.yml' }
let(:expandset) { Set.new }
let(:context_params) { { project: project, sha: '123456', user: user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
 
let(:file_content) do
<<~HEREDOC
Loading
Loading
@@ -21,10 +22,13 @@ describe Gitlab::Ci::Config::External::Mapper do
 
before do
stub_full_request(remote_url).to_return(body: file_content)
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
 
describe '#process' do
subject { described_class.new(values, project: project, sha: '123456', user: user, expandset: expandset).process }
subject { described_class.new(values, context).process }
 
context "when single 'include' keyword is defined" do
context 'when the string is a local file' do
Loading
Loading
Loading
Loading
@@ -9,12 +9,16 @@ describe Gitlab::Ci::Config::External::Processor do
set(:another_project) { create(:project, :repository) }
set(:user) { create(:user) }
 
let(:expandset) { Set.new }
let(:sha) { '12345' }
let(:processor) { described_class.new(values, project: project, sha: '12345', user: user, expandset: expandset) }
let(:context_params) { { project: project, sha: sha, user: user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:processor) { described_class.new(values, context) }
 
before do
project.add_developer(user)
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
 
describe "#perform" do
Loading
Loading
Loading
Loading
@@ -7,6 +7,11 @@ describe Gitlab::Ci::Config do
 
set(:user) { create(:user) }
 
before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
end
let(:config) do
described_class.new(yml, project: nil, sha: nil, user: nil)
end
Loading
Loading
@@ -303,6 +308,49 @@ describe Gitlab::Ci::Config do
end
end
 
context "when it takes too long to evaluate includes" do
before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
.and_call_original
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:set_deadline)
.with(described_class::TIMEOUT_SECONDS)
.and_call_original
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:execution_expired?)
.and_return(true)
end
it 'raises error TimeoutError' do
expect(Gitlab::Sentry).to receive(:track_exception)
expect { config }.to raise_error(
described_class::ConfigError,
'Resolving config took longer than expected'
)
end
end
context 'when context expansion timeout is disabled' do
before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:check_execution_time!)
.and_call_original
allow(Feature)
.to receive(:enabled?)
.with(:ci_limit_yaml_expansion, project, default_enabled: true)
.and_return(false)
end
it 'does not raises errors' do
expect { config }.not_to raise_error
end
end
describe 'external file version' do
context 'when external local file SHA is defined' do
it 'is using a defined value' do
Loading
Loading
Loading
Loading
@@ -403,12 +403,30 @@ describe API::Internal::Base do
end
 
context 'when receive_max_input_size has been updated' do
it 'returns custom git config' do
before do
allow(Gitlab::CurrentSettings).to receive(:receive_max_input_size) { 1 }
end
 
it 'returns custom git config' do
push(key, project)
 
expect(json_response["git_config_options"]).to be_present
expect(json_response["git_config_options"]).to include("uploadpack.allowFilter=true")
expect(json_response["git_config_options"]).to include("uploadpack.allowAnySHA1InWant=true")
end
context 'when gitaly_upload_pack_filter feature flag is disabled' do
before do
stub_feature_flags(gitaly_upload_pack_filter: { enabled: false, thing: project })
end
it 'does not include allowFilter and allowAnySha1InWant in the git config options' do
push(key, project)
expect(json_response["git_config_options"]).to be_present
expect(json_response["git_config_options"]).not_to include("uploadpack.allowFilter=true")
expect(json_response["git_config_options"]).not_to include("uploadpack.allowAnySHA1InWant=true")
end
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment