debian-mirror-gitlab/spec/finders/ci/variables_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.8 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::VariablesFinder do
2021-04-29 21:17:54 +05:30
shared_examples 'scoped variables' do
describe '#initialize' do
subject { described_class.new(owner, params) }
2020-07-28 23:09:34 +05:30
2021-04-29 21:17:54 +05:30
context 'without key filter' do
let!(:params) { {} }
2020-07-28 23:09:34 +05:30
2021-04-29 21:17:54 +05:30
it 'raises an error' do
expect { subject }.to raise_error(ArgumentError, 'Please provide params[:key]')
end
2020-07-28 23:09:34 +05:30
end
end
2021-04-29 21:17:54 +05:30
describe '#execute' do
subject { described_class.new(owner.reload, params).execute }
2020-07-28 23:09:34 +05:30
2021-04-29 21:17:54 +05:30
context 'with key filter' do
let!(:params) { { key: 'key1' } }
2020-07-28 23:09:34 +05:30
2021-04-29 21:17:54 +05:30
it 'returns var1' do
expect(subject).to contain_exactly(var1)
end
2020-07-28 23:09:34 +05:30
end
2021-04-29 21:17:54 +05:30
context 'with key and environment_scope filter' do
let!(:params) { { key: 'key2', filter: { environment_scope: 'staging' } } }
2020-07-28 23:09:34 +05:30
2021-04-29 21:17:54 +05:30
it 'returns var2' do
expect(subject).to contain_exactly(var2)
end
2020-07-28 23:09:34 +05:30
end
end
end
2021-04-29 21:17:54 +05:30
context 'for a project' do
let(:owner) { create(:project) }
let!(:var1) { create(:ci_variable, project: owner, key: 'key1', environment_scope: 'staging') }
let!(:var2) { create(:ci_variable, project: owner, key: 'key2', environment_scope: 'staging') }
let!(:var3) { create(:ci_variable, project: owner, key: 'key2', environment_scope: 'production') }
include_examples 'scoped variables'
end
context 'for a group' do
let(:owner) { create(:group) }
let!(:var1) { create(:ci_group_variable, group: owner, key: 'key1', environment_scope: 'staging') }
let!(:var2) { create(:ci_group_variable, group: owner, key: 'key2', environment_scope: 'staging') }
let!(:var3) { create(:ci_group_variable, group: owner, key: 'key2', environment_scope: 'production') }
include_examples 'scoped variables'
end
2020-07-28 23:09:34 +05:30
end