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

gitlab_shell_setup.rb « support « spec « gitlab-shell « ruby - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eddd2d1412a5efaaf3e1142a8eaefc90a7d92a62 (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
RSpec.shared_context 'gitlab shell', shared_context: :metadata do
  def original_root_path
    ROOT_PATH
  end

  def config_path
    File.join(tmp_root_path, 'config.yml')
  end

  def write_config(config)
    File.open(config_path, 'w') do |f|
      f.write(config.to_yaml)
    end
  end

  def tmp_root_path
    @tmp_root_path ||= File.realpath(Dir.mktmpdir)
  end

  def mock_server(server)
    raise NotImplementedError.new(
      'mock_server method must be implemented in order to include gitlab shell context'
    )
  end

  # This has to be a relative path shorter than 100 bytes due to
  # limitations in how Unix sockets work.
  def tmp_socket_path
    'tmp/gitlab-shell-socket'
  end

  let(:gitlab_shell_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell') }

  before(:all) do
    FileUtils.mkdir_p(File.dirname(tmp_socket_path))
    FileUtils.touch(File.join(tmp_root_path, '.gitlab_shell_secret'))

    @server = HTTPUNIXServer.new(BindAddress: tmp_socket_path)

    mock_server(@server)

    @webrick_thread = Thread.new { @server.start }

    sleep(0.1) while @webrick_thread.alive? && @server.status != :Running
    raise "Couldn't start stub GitlabNet server" unless @server.status == :Running
    system(original_root_path, 'bin/compile')

    copy_dirs = ['bin', 'lib']
    FileUtils.rm_rf(copy_dirs.map { |d| File.join(tmp_root_path, d) })
    FileUtils.cp_r(copy_dirs, tmp_root_path)
  end

  after(:all) do
    @server.shutdown if @server
    @webrick_thread.join if @webrick_thread
    FileUtils.rm_rf(tmp_root_path)
  end
end