Welcome to mirror list, hosted at ThFree Co, Russian Federation.

store_spec.rb « etag_caching « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 46195e64715faaa4c4c842f81d5a319193c44c9a (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::EtagCaching::Store, :clean_gitlab_redis_shared_state do
  let(:store) { described_class.new }

  describe '#get' do
    subject { store.get(key) }

    context 'with invalid keys' do
      let(:key) { 'a' }

      it 'raises errors' do
        expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original

        expect { subject }.to raise_error Gitlab::EtagCaching::Store::InvalidKeyError
      end

      it 'does not raise errors in production' do
        expect(store).to receive(:skip_validation?).and_return true
        expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)

        subject
      end
    end

    context 'with GraphQL keys' do
      let(:key) { '/api/graphql:pipelines/id/5' }

      it 'returns a stored value' do
        etag = store.touch(key)

        is_expected.to eq(etag)
      end
    end

    context 'with RESTful keys' do
      let(:key) { '/my-group/my-project/builds/234.json' }

      it 'returns a stored value' do
        etag = store.touch(key)

        is_expected.to eq(etag)
      end
    end
  end

  describe '#touch' do
    subject { store.touch(key) }

    context 'with invalid keys' do
      let(:key) { 'a' }

      it 'raises errors' do
        expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original

        expect { subject }.to raise_error Gitlab::EtagCaching::Store::InvalidKeyError
      end
    end

    context 'with GraphQL keys' do
      let(:key) { '/api/graphql:pipelines/id/5' }

      it 'stores and returns a value' do
        etag = store.touch(key)

        expect(etag).to be_present
        expect(store.get(key)).to eq(etag)
      end
    end

    context 'with RESTful keys' do
      let(:key) { '/my-group/my-project/builds/234.json' }

      it 'stores and returns a value' do
        etag = store.touch(key)

        expect(etag).to be_present
        expect(store.get(key)).to eq(etag)
      end
    end
  end
end