diff options
| author | Can Eldem <celdem@gitlab.com> | 2020-07-10 16:41:15 +0000 |
|---|---|---|
| committer | Can Eldem <celdem@gitlab.com> | 2020-07-10 16:41:15 +0000 |
| commit | c17546f6cfccf07d27f7984321fe62a7788e8da1 (patch) | |
| tree | 54093c956c0f4dcf4c2ad352847017aee9a88edc /spec/support/integration_test_helper.rb | |
| parent | c7385965b4166fb6ab2db3387c67cd54aef1b8df (diff) | |
| parent | 36cdb0040abda394264455a1fdf3d6782af95ceb (diff) | |
Merge branch '217897-isolated-omnibus-lm' into 'master'v3.17.0
Isolate license_management ruby from project ruby
See merge request gitlab-org/security-products/license-management!181
Diffstat (limited to 'spec/support/integration_test_helper.rb')
| -rw-r--r-- | spec/support/integration_test_helper.rb | 94 |
1 files changed, 1 insertions, 93 deletions
diff --git a/spec/support/integration_test_helper.rb b/spec/support/integration_test_helper.rb index 7dc64fe..244f363 100644 --- a/spec/support/integration_test_helper.rb +++ b/spec/support/integration_test_helper.rb @@ -1,95 +1,4 @@ module IntegrationTestHelper - class Report - attr_reader :report - - def initialize(raw) - @report = JSON.parse(raw, symbolize_names: true) - end - - def [](key) - report[key] - end - - def dependency_names - report[:dependencies].map { |x| x[:name] } - end - - def licenses_for(name) - (find(name) || {}).fetch(:licenses, []) - end - - def find(name) - report[:dependencies].find do |dependency| - dependency[:name] == name - end - end - - def nil? - report.nil? - end - - def to_hash - to_h - end - - def to_h - report - end - end - - class IntegrationTestRunner - attr_reader :project_path - - def initialize(project_path = Pathname.pwd.join('tmp').join(SecureRandom.uuid)) - FileUtils.mkdir_p(project_path) - @project_path = Pathname(project_path) - end - - def add_file(name, content = nil) - full_path = project_path.join(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') - if branch.match?(/\b[0-9a-f]{5,40}\b/) - execute({}, 'git', 'clone', '--quiet', repo, project_path.to_s) - Dir.chdir project_path do - execute({}, 'git', 'checkout', branch) - end - else - execute({}, 'git', 'clone', '--quiet', '--depth=1', '--single-branch', '--branch', branch, repo, project_path.to_s) - end - end - - def scan(env: {}) - execute(env, 'mkdir -p pkg/ && gem build --silent -o pkg/license-management-test.gem ./*.gemspec') - Dir.chdir project_path do - merged_env = { 'CI_PROJECT_DIR' => project_path.to_s }.merge(env) - return {} unless execute(merged_env, "#{License::Management.root.join('run.sh')} analyze .") - - report_path = project_path.join('gl-license-scanning-report.json') - return {} unless report_path.exist? - - Report.new(report_path.read) - end - 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 project_path.exist? - end - end - def private_npm_host @private_npm_host ||= ENV.fetch('PRIVATE_NPM_HOST').tap do |host| add_host(host, ENV.fetch('PRIVATE_NPM_IP')) @@ -109,11 +18,10 @@ module IntegrationTestHelper end def runner(*args) - @runner ||= IntegrationTestRunner.new(*args) + @runner ||= ProjectHelper.new(*args) end def add_host(name, ip) - return unless ENV['LM_HOME'] return if system("grep #{name} /etc/hosts") system("echo '#{ip} #{name}' >> /etc/hosts") |
