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
|
module IntegrationTestHelper
class IntegrationTestRunner
attr_reader :project_path
def initialize(project_path = File.join(Dir.pwd, 'tmp', SecureRandom.uuid))
FileUtils.mkdir_p(project_path)
@project_path = project_path
end
def add_file(name, content = nil)
full_path = Pathname.new(File.join(project_path, name))
FileUtils.mkdir_p(full_path.dirname)
IO.write(full_path, block_given? ? yield : content)
end
def mount(dir:)
FileUtils.cp_r("#{dir}/.", project_path)
end
def clone(repo, branch: 'master')
execute({}, "git", "clone", '--quiet', repo, project_path)
Dir.chdir project_path do
execute({}, "git", "checkout", branch)
end
end
def scan(env: {})
return {} unless execute(env, './bin/docker-test', project_path)
report_path = "#{project_path}/gl-license-management-report.json"
return {} unless File.exist?(report_path)
JSON.parse(IO.read(report_path), symbolize_names: true)
end
def execute(env = {}, *args)
Bundler.with_unbundled_env do
system(env, *args, exception: true)
end
end
def cleanup
FileUtils.rm_rf(project_path) if Dir.exist?(project_path)
end
end
def runner(*args)
@runner ||= IntegrationTestRunner.new(*args)
end
def find_in(report, name)
report[:dependencies].find do |dependency|
dependency[:name] == name
end
end
end
|