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

seed_helper.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9628762d46a01328d1b86c49f3bbb0d6222e575f (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
# frozen_string_literal: true

require_relative 'test_env'

# This file is specific to specs in spec/lib/gitlab/git/

SEED_STORAGE_PATH      = Gitlab::GitalyClient::StorageSettings.allow_disk_access { TestEnv.repos_path }
TEST_REPO_PATH         = 'gitlab-git-test.git'
TEST_NORMAL_REPO_PATH  = 'not-bare-repo.git'
TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'
TEST_BROKEN_REPO_PATH  = 'broken-repo.git'

module SeedHelper
  GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __dir__)

  def ensure_seeds
    if File.exist?(SEED_STORAGE_PATH)
      FileUtils.rm_r(SEED_STORAGE_PATH)
    end

    FileUtils.mkdir_p(SEED_STORAGE_PATH)

    create_bare_seeds
    create_normal_seeds
    create_mutable_seeds
    create_broken_seeds
  end

  def create_bare_seeds
    system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{GITLAB_GIT_TEST_REPO_URL}),
           chdir: SEED_STORAGE_PATH,
           out: '/dev/null',
           err: '/dev/null')
  end

  def create_normal_seeds
    system(git_env, *%W(#{Gitlab.config.git.bin_path} clone #{TEST_REPO_PATH} #{TEST_NORMAL_REPO_PATH}),
           chdir: SEED_STORAGE_PATH,
           out: '/dev/null',
           err: '/dev/null')
  end

  def create_mutable_seeds
    system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} #{TEST_MUTABLE_REPO_PATH}),
           chdir: SEED_STORAGE_PATH,
           out: '/dev/null',
           err: '/dev/null')

    mutable_repo_full_path = File.join(SEED_STORAGE_PATH, TEST_MUTABLE_REPO_PATH)
    system(git_env, *%W(#{Gitlab.config.git.bin_path} branch -t feature origin/feature),
           chdir: mutable_repo_full_path, out: '/dev/null', err: '/dev/null')

    system(git_env, *%W(#{Gitlab.config.git.bin_path} remote add expendable #{GITLAB_GIT_TEST_REPO_URL}),
           chdir: mutable_repo_full_path, out: '/dev/null', err: '/dev/null')
  end

  def create_broken_seeds
    system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} #{TEST_BROKEN_REPO_PATH}),
           chdir: SEED_STORAGE_PATH,
           out: '/dev/null',
           err: '/dev/null')

    refs_path = File.join(SEED_STORAGE_PATH, TEST_BROKEN_REPO_PATH, 'refs')

    FileUtils.rm_r(refs_path)
  end
end