summaryrefslogtreecommitdiff
path: root/spec/support/helpers/fake_blob_helpers.rb
blob: 47fb9a345a39fce2d90f1681c3e3b8276de145e2 (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
# frozen_string_literal: true

module FakeBlobHelpers
  class FakeBlob
    include BlobLike

    attr_reader :path, :size, :data, :lfs_oid, :lfs_size, :mode

    def initialize(path: 'file.txt', size: 1.kilobyte, data: 'foo', binary: false, lfs: nil, mode: nil)
      @path = path
      @size = size
      @data = data
      @binary = binary
      @mode = mode

      @lfs_pointer = lfs.present?
      if @lfs_pointer
        @lfs_oid = SecureRandom.hex(20)
        @lfs_size = 1.megabyte
      end
    end

    alias_method :name, :path

    def id
      "00000000"
    end

    def commit_id
      "11111111"
    end

    def binary_in_repo?
      @binary
    end

    def external_storage
      :lfs if @lfs_pointer
    end

    alias_method :external_size, :lfs_size
  end

  def fake_blob(**kwargs)
    container = kwargs.delete(:container) || project

    Blob.decorate(FakeBlob.new(**kwargs), container)
  end
end