diff options
| author | mo khan <mo.khan@gmail.com> | 2020-04-02 15:11:12 +0000 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-04-02 15:11:12 +0000 |
| commit | 2d200e2bcecb91eadc5ee211f5bb65aafa645054 (patch) | |
| tree | 9749333a7c8878b833b4642afe3071cf1c14012c /spec/support/integration_test_helper.rb | |
| parent | 43bcbbd04342faa497725c5b0be3c6d944d850da (diff) | |
| parent | bfd7459419921ff37ee500f0698862eea6788675 (diff) | |
Merge branch '10128-go-modules' into 'master'v3.5.0
Improve license detection in go modules projects
See merge request gitlab-org/security-products/license-management!129
Diffstat (limited to 'spec/support/integration_test_helper.rb')
| -rw-r--r-- | spec/support/integration_test_helper.rb | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/spec/support/integration_test_helper.rb b/spec/support/integration_test_helper.rb index c4c0d88..bcc5c1f 100644 --- a/spec/support/integration_test_helper.rb +++ b/spec/support/integration_test_helper.rb @@ -1,4 +1,42 @@ 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)[: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 @@ -30,7 +68,7 @@ module IntegrationTestHelper report_path = "#{project_path}/gl-license-management-report.json" return {} unless File.exist?(report_path) - JSON.parse(IO.read(report_path), symbolize_names: true) + Report.new(IO.read(report_path)) end def execute(env = {}, *args) @@ -47,10 +85,4 @@ module IntegrationTestHelper def runner(*args) @runner ||= IntegrationTestRunner.new(*args) end - - def find_in(report, name) - report[:dependencies].find do |dependency| - dependency[:name] == name - end - end end |
