blob: 2e8af7a9c44d26add8d0c7e326f66d6dd7e55a63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Cache::Metadata, feature_category: :source_code_management do
subject(:attributes) do
described_class.new(
caller_id: caller_id,
cache_identifier: cache_identifier,
feature_category: feature_category,
backing_resource: backing_resource
)
end
let(:caller_id) { 'caller-id' }
let(:cache_identifier) { 'ApplicationController#show' }
let(:feature_category) { :source_code_management }
let(:backing_resource) { :unknown }
describe '#initialize' do
context 'when optional arguments are not set' do
before do
Gitlab::ApplicationContext.push(caller_id: 'context-id')
end
it 'sets default value for them' do
attributes = described_class.new(
cache_identifier: cache_identifier,
feature_category: feature_category
)
expect(attributes.backing_resource).to eq(:unknown)
expect(attributes.caller_id).to eq('context-id')
end
end
context 'when invalid feature category is set' do
let(:feature_category) { :not_supported }
it { expect { attributes }.to raise_error(RuntimeError) }
context 'when on production' do
before do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
end
it 'does not raise an exception' do
expect { attributes }.not_to raise_error
expect(attributes.feature_category).to eq('unknown')
end
end
end
context 'when backing resource is not supported' do
let(:backing_resource) { 'foo' }
it { expect { attributes }.to raise_error(RuntimeError) }
context 'when on production' do
before do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
end
it 'does not raise an exception' do
expect { attributes }.not_to raise_error
end
end
end
end
describe '#caller_id' do
subject { attributes.caller_id }
it { is_expected.to eq caller_id }
end
describe '#cache_identifier' do
subject { attributes.cache_identifier }
it { is_expected.to eq cache_identifier }
end
describe '#feature_category' do
subject { attributes.feature_category }
it { is_expected.to eq feature_category }
end
describe '#backing_resource' do
subject { attributes.backing_resource }
it { is_expected.to eq backing_resource }
end
end
|