diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-30 23:05:42 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-04-02 00:08:43 -0600 |
| commit | bfd7459419921ff37ee500f0698862eea6788675 (patch) | |
| tree | 9749333a7c8878b833b4642afe3071cf1c14012c /spec/support | |
| parent | 43bcbbd04342faa497725c5b0be3c6d944d850da (diff) | |
Reproduce failure with go modules scanning
* Install sudo for existing configurations
* Detect dependencies in a gomodules project
* Add CHANGELOG entry and bump version
* Symlink to $GOPATH for non go modules projects
* Remove problematic go get setup
Diffstat (limited to 'spec/support')
| -rw-r--r-- | spec/support/integration_test_helper.rb | 46 | ||||
| -rw-r--r-- | spec/support/matchers.rb | 3 | ||||
| -rw-r--r-- | spec/support/shared.rb | 2 |
3 files changed, 42 insertions, 9 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 diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 595cd17..66bb92c 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -2,8 +2,9 @@ RSpec::Matchers.define :match_schema do |version: '2.0'| def schema_for(version) License::Management.root.join("spec/fixtures/schema/v#{version}.json").to_s end + match do |actual| - !actual.nil? && (@errors = JSON::Validator.fully_validate(schema_for(version), actual)).empty? + !actual.nil? && (@errors = JSON::Validator.fully_validate(schema_for(version), actual.to_h)).empty? end failure_message do |response| diff --git a/spec/support/shared.rb b/spec/support/shared.rb index ba3d3cc..51b161a 100644 --- a/spec/support/shared.rb +++ b/spec/support/shared.rb @@ -11,7 +11,7 @@ RSpec.shared_examples "each report version" do |language, package_manager, branc it 'matches the expected report' do actual = runner.scan(env: { 'LM_REPORT_VERSION' => version }) - expect(JSON.pretty_generate(actual)).to eq(JSON.pretty_generate(expected_content)) + expect(JSON.pretty_generate(actual.to_h)).to eq(JSON.pretty_generate(expected_content)) expect(actual).to match_schema(version: version) end end |
