17417: Add arm64 packages for our Golang components.
[arvados.git] / services / api / test / helpers / git_test_helper.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'fileutils'
6 require 'tmpdir'
7
8 # Commit log for "foo" repository in test.git.tar
9 # master is the main branch
10 # b1 is a branch off of master
11 # tag1 is a tag
12 #
13 # 1de84a8 * b1
14 # 077ba2a * master
15 # 4fe459a * tag1
16 # 31ce37f * foo
17
18 module GitTestHelper
19   def self.included base
20     base.setup do
21       # Extract the test repository data into the default test
22       # environment's Rails.configuration.Git.Repositories. (We
23       # don't use that config setting here, though: it doesn't seem
24       # worth the risk of stepping on a real git repo root.)
25       @tmpdir = Rails.root.join 'tmp', 'git'
26       FileUtils.mkdir_p @tmpdir
27       system("tar", "-xC", @tmpdir.to_s, "-f", "test/test.git.tar")
28       Rails.configuration.Git.Repositories = "#{@tmpdir}/test"
29       Rails.configuration.Containers.JobsAPI.GitInternalDir = "#{@tmpdir}/internal.git"
30     end
31
32     base.teardown do
33       FileUtils.remove_entry CommitsHelper.cache_dir_base, true
34       FileUtils.mkdir_p @tmpdir
35       system("tar", "-xC", @tmpdir.to_s, "-f", "test/test.git.tar")
36     end
37   end
38
39   def internal_tag tag
40     IO.read "|git --git-dir #{Rails.configuration.Containers.JobsAPI.GitInternalDir.shellescape} log --format=format:%H -n1 #{tag.shellescape}"
41   end
42
43   # Intercept fetch_remote_repository and fetch from a specified url
44   # or local fixture instead of the remote url requested. fakeurl can
45   # be a url (probably starting with file:///) or the name of a
46   # fixture (as a symbol)
47   def fetch_remote_from_local_repo url, fakeurl
48     if fakeurl.is_a? Symbol
49       fakeurl = 'file://' + repositories(fakeurl).server_path
50     end
51     CommitsHelper.expects(:fetch_remote_repository).once.with do |gitdir, giturl|
52       if giturl == url
53         CommitsHelper.unstub(:fetch_remote_repository)
54         CommitsHelper.fetch_remote_repository gitdir, fakeurl
55         true
56       end
57     end
58   end
59 end