blob: 41d7ce5d178b58ef3b7e7b445e2ced1a81fb7844 (
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
|
# frozen_string_literal: true
require 'tmpdir'
module QA
module Runtime
module Fixtures
include Support::API
TemplateNotFoundError = Class.new(RuntimeError)
def fetch_template_from_api(api_path, key)
request = Runtime::API::Request.new(api_client, "/templates/#{api_path}/#{key}")
response = get(request.url)
unless response.code == HTTP_STATUS_OK
raise TemplateNotFoundError, "Template at #{request.mask_url} could not be found (#{response.code}): `#{response}`."
end
parse_body(response)[:content]
end
def with_fixtures(fixtures)
dir = Dir.mktmpdir
fixtures.each do |file_def|
path = File.join(dir, file_def[:file_path])
FileUtils.mkdir_p(File.dirname(path))
File.write(path, file_def[:content])
end
yield dir
ensure
FileUtils.remove_entry(dir, true)
end
def read_fixture(fixture_path, file_name)
file_path = Pathname
.new(__dir__)
.join("../fixtures/#{fixture_path}/#{file_name}")
File.read(file_path)
end
private
def api_client
@api_client ||= Runtime::API::Client.new(:gitlab)
end
end
end
end
|