summaryrefslogtreecommitdiff
path: root/spec/lib/object_storage/pending_direct_upload_spec.rb
blob: af08b9c81888ccf4b557a89b62990a0bf96001f2 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ObjectStorage::PendingDirectUpload, :clean_gitlab_redis_shared_state, feature_category: :shared do
  let(:location_identifier) { :artifacts }
  let(:path) { 'some/path/123' }

  describe '.prepare' do
    it 'creates a redis entry for the given location identifier and path' do
      freeze_time do
        described_class.prepare(location_identifier, path)

        ::Gitlab::Redis::SharedState.with do |redis|
          key = described_class.key(location_identifier, path)
          expect(redis.hget('pending_direct_uploads', key)).to eq(Time.current.utc.to_i.to_s)
        end
      end
    end
  end

  describe '.exists?' do
    let(:path) { 'some/path/123' }

    subject { described_class.exists?(given_identifier, given_path) }

    before do
      described_class.prepare(location_identifier, path)
    end

    context 'when there is a matching redis entry for the given path under the location identifier' do
      let(:given_identifier) { location_identifier }
      let(:given_path) { path }

      it { is_expected.to eq(true) }
    end

    context 'when there is a matching redis entry for the given path under a different location identifier' do
      let(:given_identifier) { :uploads }
      let(:given_path) { path }

      it { is_expected.to eq(false) }
    end

    context 'when there is no matching redis entry for the given path under the location identifier' do
      let(:given_identifier) { location_identifier }
      let(:given_path) { 'wrong/path/123' }

      it { is_expected.to eq(false) }
    end
  end

  describe '.complete' do
    it 'deletes the redis entry for the given path' do
      described_class.prepare(location_identifier, path)

      expect(described_class.exists?(location_identifier, path)).to eq(true)

      described_class.complete(location_identifier, path)

      expect(described_class.exists?(location_identifier, path)).to eq(false)
    end
  end

  describe '.key' do
    subject { described_class.key(location_identifier, path) }

    it { is_expected.to eq("#{location_identifier}:#{path}") }
  end
end