summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorCan Eldem <celdem@gitlab.com>2020-06-08 12:16:35 +0000
committerCan Eldem <celdem@gitlab.com>2020-06-08 12:16:35 +0000
commit5eef2e4c1a5c28f4e2b8e48e4701dae56264a979 (patch)
treef853dc1c8601fb4222908f2ce8d4e03880367db3 /spec
parent12ef778891c4bf9fae19ffdc9d566fc7ab309957 (diff)
parent55d3e5288826e21286054ed7cbaaec15e037f1dd (diff)
Merge branch 'asdf-java-version' into 'master'v3.11.2
Load the configured version of Java/Python See merge request gitlab-org/security-products/license-management!163
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/java/maven_spec.rb42
-rw-r--r--spec/integration/python/pip_spec.rb42
-rw-r--r--spec/support/integration_test_helper.rb20
3 files changed, 94 insertions, 10 deletions
diff --git a/spec/integration/java/maven_spec.rb b/spec/integration/java/maven_spec.rb
index 85637b2..9230a9f 100644
--- a/spec/integration/java/maven_spec.rb
+++ b/spec/integration/java/maven_spec.rb
@@ -100,4 +100,46 @@ RSpec.describe "maven" do
specify { expect(report.dependency_names).to match_array(['jackson-core']) }
specify { expect(report.licenses_for('jackson-core')).to match_array(['Apache-2.0']) }
end
+
+ context "when specifying the version of java using environment variables" do
+ let(:output_file) { Pathname.new(runner.project_path.join('output.txt')) }
+
+ before do
+ runner.add_file('custom.sh') do
+ <<~SCRIPT
+ #!/bin/bash -l
+
+ java -version &> '#{output_file}'
+ SCRIPT
+ end
+ end
+
+ it 'prioritizes `LM_JAVA_VERSION` over the `ASDF_JAVA_VERSION`' do
+ runner.scan(env: {
+ 'ASDF_JAVA_VERSION' => 'adopt-openjdk-11.0.7+10',
+ 'LM_JAVA_VERSION' => '8',
+ 'SETUP_CMD' => 'bash custom.sh'
+ })
+
+ expect(output_file).to exist
+ expect(output_file.read).to include('openjdk version "1.8.0_242"')
+ end
+
+ it 'reads the ASDF_JAVA_VERSION' do
+ runner.scan(env: {
+ 'ASDF_JAVA_VERSION' => 'adopt-openjdk-11.0.7+10',
+ 'SETUP_CMD' => 'bash custom.sh'
+ })
+
+ expect(output_file).to exist
+ expect(output_file.read).to include('openjdk version "11.0.7"')
+ end
+
+ it 'defaults to java 8' do
+ runner.scan(env: { 'SETUP_CMD' => 'bash custom.sh' })
+
+ expect(output_file).to exist
+ expect(output_file.read).to include('openjdk version "1.8.0_242"')
+ end
+ end
end
diff --git a/spec/integration/python/pip_spec.rb b/spec/integration/python/pip_spec.rb
index 0ba3d0e..e808188 100644
--- a/spec/integration/python/pip_spec.rb
+++ b/spec/integration/python/pip_spec.rb
@@ -157,4 +157,46 @@ setup(
expect(report.licenses_for('requests')).to match_array(['Apache-2.0'])
end
end
+
+ context "when specifying the version of Python using environment variables" do
+ let(:output_file) { Pathname.new(runner.project_path.join('output.txt')) }
+
+ before do
+ runner.add_file('custom.sh') do
+ <<~SCRIPT
+ #!/bin/bash -l
+
+ python --version &> '#{output_file}'
+ SCRIPT
+ end
+ end
+
+ it 'prioritizes `LM_PYTHON_VERSION` over the `ASDF_PYTHON_VERSION`' do
+ runner.scan(env: {
+ 'ASDF_PYTHON_VERSION' => '3.8.2',
+ 'LM_PYTHON_VERSION' => '2.7.18',
+ 'SETUP_CMD' => 'bash custom.sh'
+ })
+
+ expect(output_file).to exist
+ expect(output_file.read).to include('2.7.18')
+ end
+
+ it 'reads the ASDF_PYTHON_VERSION' do
+ runner.scan(env: {
+ 'ASDF_PYTHON_VERSION' => '3.8.2',
+ 'SETUP_CMD' => 'bash custom.sh'
+ })
+
+ expect(output_file).to exist
+ expect(output_file.read).to include('3.8.2')
+ end
+
+ it 'defaults to Python 3' do
+ runner.scan(env: { 'SETUP_CMD' => 'bash custom.sh' })
+
+ expect(output_file).to exist
+ expect(output_file.read).to include('3.8.2')
+ end
+ end
end
diff --git a/spec/support/integration_test_helper.rb b/spec/support/integration_test_helper.rb
index aa3f0c0..f474265 100644
--- a/spec/support/integration_test_helper.rb
+++ b/spec/support/integration_test_helper.rb
@@ -40,13 +40,13 @@ module IntegrationTestHelper
class IntegrationTestRunner
attr_reader :project_path
- def initialize(project_path = File.join(Dir.pwd, 'tmp', SecureRandom.uuid))
+ def initialize(project_path = Pathname.pwd.join('tmp').join(SecureRandom.uuid))
FileUtils.mkdir_p(project_path)
- @project_path = project_path
+ @project_path = Pathname(project_path)
end
def add_file(name, content = nil)
- full_path = Pathname.new(File.join(project_path, name))
+ full_path = project_path.join(name)
FileUtils.mkdir_p(full_path.dirname)
IO.write(full_path, block_given? ? yield : content)
end
@@ -57,22 +57,22 @@ module IntegrationTestHelper
def clone(repo, branch: 'master')
if branch.match?(/\b[0-9a-f]{5,40}\b/)
- execute({}, 'git', 'clone', '--quiet', repo, project_path)
+ 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)
+ execute({}, 'git', 'clone', '--quiet', '--depth=1', '--single-branch', '--branch', branch, repo, project_path.to_s)
end
end
def scan(env: {})
- return {} unless execute(env, './bin/docker-test', project_path)
+ return {} unless execute(env, './bin/docker-test', project_path.to_s)
- report_path = "#{project_path}/gl-license-management-report.json"
- return {} unless File.exist?(report_path)
+ report_path = project_path.join('gl-license-management-report.json')
+ return {} unless report_path.exist?
- Report.new(IO.read(report_path))
+ Report.new(report_path.read)
end
def execute(env = {}, *args)
@@ -82,7 +82,7 @@ module IntegrationTestHelper
end
def cleanup
- FileUtils.rm_rf(project_path) if Dir.exist?(project_path)
+ FileUtils.rm_rf(project_path) if project_path.exist?
end
end