diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/services/ci/list_config_variables_service_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/services/ci/list_config_variables_service_spec.rb')
-rw-r--r-- | spec/services/ci/list_config_variables_service_spec.rb | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/spec/services/ci/list_config_variables_service_spec.rb b/spec/services/ci/list_config_variables_service_spec.rb index 95c98c2b5ef..1735f4cfc97 100644 --- a/spec/services/ci/list_config_variables_service_spec.rb +++ b/spec/services/ci/list_config_variables_service_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Ci::ListConfigVariablesService do +RSpec.describe Ci::ListConfigVariablesService, :use_clean_rails_memory_store_caching do + include ReactiveCachingHelpers + let(:project) { create(:project, :repository) } let(:user) { project.creator } let(:service) { described_class.new(project, user) } @@ -31,6 +33,10 @@ RSpec.describe Ci::ListConfigVariablesService do } end + before do + synchronous_reactive_cache(service) + end + it 'returns variable list' do expect(subject['KEY1']).to eq({ value: 'val 1', description: 'description 1' }) expect(subject['KEY2']).to eq({ value: 'val 2', description: '' }) @@ -65,6 +71,8 @@ RSpec.describe Ci::ListConfigVariablesService do HEREDOC end end + + synchronous_reactive_cache(service) end it 'returns variable list' do @@ -77,6 +85,10 @@ RSpec.describe Ci::ListConfigVariablesService do let(:sha) { 'invalid-sha' } let(:ci_config) { nil } + before do + synchronous_reactive_cache(service) + end + it 'returns empty json' do expect(subject).to eq({}) end @@ -96,11 +108,44 @@ RSpec.describe Ci::ListConfigVariablesService do } end + before do + synchronous_reactive_cache(service) + end + it 'returns empty result' do expect(subject).to eq({}) end end + context 'when reading from cache' do + let(:sha) { 'master' } + let(:ci_config) { {} } + let(:reactive_cache_params) { [sha] } + let(:return_value) { { 'KEY1' => { value: 'val 1', description: 'description 1' } } } + + before do + stub_reactive_cache(service, return_value, reactive_cache_params) + end + + it 'returns variable list' do + expect(subject).to eq(return_value) + end + end + + context 'when the cache is empty' do + let(:sha) { 'master' } + let(:ci_config) { {} } + let(:reactive_cache_params) { [sha] } + + it 'returns nil and enquques the worker to fill cache' do + expect(ExternalServiceReactiveCachingWorker) + .to receive(:perform_async) + .with(service.class, service.id, *reactive_cache_params) + + expect(subject).to be_nil + end + end + private def stub_gitlab_ci_yml_for_sha(sha, result) |