From cea7d78e2d7f1a8f98880819b8589925b5daef1a Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 14 Sep 2020 16:11:33 -0600 Subject: Write a test to scan a java project --- spec/gemnasium_maven_spec.rb | 21 +++++++++++++++++++++ spec/spec_helper.rb | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 spec/gemnasium_maven_spec.rb (limited to 'spec') diff --git a/spec/gemnasium_maven_spec.rb b/spec/gemnasium_maven_spec.rb new file mode 100644 index 0000000..63c9aae --- /dev/null +++ b/spec/gemnasium_maven_spec.rb @@ -0,0 +1,21 @@ +RSpec.describe 'gemnasium-maven' do + context "when scanning a java project with packages from a custom source" do + subject do + Dir.chdir Pathname.pwd.join('src/gemnasium-maven') do + system("docker build --network=host -t #{docker_image} .") + + if system([ :docker, :run, '-it', '--rm', '--volume', "#{project_path}:/tmp/app", '--network=host', '--env', 'CI_PROJECT_DIR=/tmp/app', docker_image, '/analyzer run' ].map(&:to_s).join(' ')) + report_path = project_path.join('gl-license-scanning-report.json') + report_path.exist? ? JSON.parse(report_path.read) : {} + else + {} + end + end + end + + let(:project_path) { Dir.pwd } + let(:docker_image) { 'gemnasium-maven:latest' } + + specify { expect(subject.count).to eql(1) } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 251aa51..8cfc067 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,8 @@ # it. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'json' + RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest -- cgit v1.2.3