debian-mirror-gitlab/spec/lib/gitlab/reactive_cache_set_cache_spec.rb

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

90 lines
2.1 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::ReactiveCacheSetCache, :clean_gitlab_redis_cache do
2020-04-08 14:13:33 +05:30
let_it_be(:project) { create(:project) }
2021-09-30 23:02:18 +05:30
2020-04-08 14:13:33 +05:30
let(:cache_prefix) { 'cache_prefix' }
let(:expires_in) { 10.minutes }
let(:cache) { described_class.new(expires_in: expires_in) }
describe '#cache_key' do
subject { cache.cache_key(cache_prefix) }
it 'includes the suffix' do
expect(subject).to eq "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:#{cache_prefix}:set"
end
end
describe '#read' do
subject { cache.read(cache_prefix) }
it { is_expected.to be_empty }
context 'after item added' do
before do
cache.write(cache_prefix, 'test_item')
end
it { is_expected.to contain_exactly('test_item') }
end
end
describe '#write' do
it 'writes the value to the cache' do
cache.write(cache_prefix, 'test_item')
expect(cache.read(cache_prefix)).to contain_exactly('test_item')
end
it 'sets the expiry of the set' do
cache.write(cache_prefix, 'test_item')
expect(cache.ttl(cache_prefix)).to be_within(1).of(expires_in.seconds)
end
end
describe '#clear_cache!', :use_clean_rails_redis_caching do
it 'deletes the cached items' do
# Cached key and value
Rails.cache.write('test_item', 'test_value')
# Add key to set
cache.write(cache_prefix, 'test_item')
expect(cache.read(cache_prefix)).to contain_exactly('test_item')
cache.clear_cache!(cache_prefix)
expect(cache.read(cache_prefix)).to be_empty
end
end
describe '#include?' do
subject { cache.include?(cache_prefix, 'test_item') }
it { is_expected.to be(false) }
context 'item added' do
before do
cache.write(cache_prefix, 'test_item')
end
it { is_expected.to be(true) }
end
end
2022-09-01 20:07:04 +05:30
describe 'count' do
subject { cache.count(cache_prefix) }
it { is_expected.to be(0) }
context 'item added' do
before do
cache.write(cache_prefix, 'test_item')
end
it { is_expected.to be(1) }
end
end
2020-04-08 14:13:33 +05:30
end