diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-17 13:05:06 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-03-18 10:29:39 -0600 |
| commit | b3a72f1f302ae4b3d10f1fcba847b45a3491845e (patch) | |
| tree | 219e5738406a337de81825ec46fef6474340e606 | |
| parent | 2a4bbbd4c655ac2eda4db0f9a89828be799fbca7 (diff) | |
Extract test fixtures
| -rw-r--r-- | spec/fixtures/custom-maven-settings.xml | 16 | ||||
| -rw-r--r-- | spec/fixtures/pom-public-gitlab-repository.xml | 16 | ||||
| -rw-r--r-- | spec/integration/java/maven_spec.rb | 33 | ||||
| -rw-r--r-- | spec/support/fixture_file_helper.rb | 6 |
4 files changed, 50 insertions, 21 deletions
diff --git a/spec/fixtures/custom-maven-settings.xml b/spec/fixtures/custom-maven-settings.xml new file mode 100644 index 0000000..4fa5d16 --- /dev/null +++ b/spec/fixtures/custom-maven-settings.xml @@ -0,0 +1,16 @@ +<settings> + <profiles> + <profile> + <id>custom</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <repositories> + <repository> + <id>gitlab-maven</id> + <url>https://gitlab.com/api/v4/projects/17523603/packages/maven</url> + </repository> + </repositories> + </profile> + </profiles> +</settings> diff --git a/spec/fixtures/pom-public-gitlab-repository.xml b/spec/fixtures/pom-public-gitlab-repository.xml new file mode 100644 index 0000000..4e57c79 --- /dev/null +++ b/spec/fixtures/pom-public-gitlab-repository.xml @@ -0,0 +1,16 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>com.gitlab.secure</groupId> + <artifactId>license-scanning</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>example</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>com.gitlab.xlgmokha</groupId> + <artifactId>mvn-spike</artifactId> + <version>1.2-SNAPSHOT</version> + </dependency> + </dependencies> +</project> diff --git a/spec/integration/java/maven_spec.rb b/spec/integration/java/maven_spec.rb index ad083bb..9b0ee45 100644 --- a/spec/integration/java/maven_spec.rb +++ b/spec/integration/java/maven_spec.rb @@ -5,31 +5,24 @@ RSpec.describe "maven" do describe "When the maven dependencies come from a custom public maven repository" do it 'is able to detect some of the licenses' do - runner.add_file('pom.xml') do - <<~XML -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>com.gitlab.secure</groupId> - <artifactId>license-scanning</artifactId> - <packaging>jar</packaging> - <version>1.0-SNAPSHOT</version> - <name>example</name> - <url>http://maven.apache.org</url> - <dependencies> - <dependency> - <groupId>com.gitlab.xlgmokha</groupId> - <artifactId>mvn-spike</artifactId> - <version>1.2-SNAPSHOT</version> - </dependency> - </dependencies> -</project> - XML - end + runner.add_file('pom.xml', fixture_file_content('pom-public-gitlab-repository.xml')) report = runner.scan(env: { 'CI_PROJECT_ID' => '17523603' }) expect(report).to match_schema(version: '2.0') expect(report[:dependencies]).to match_array([{ name: 'mvn-spike', url: '', description: '', paths: ['.'], licenses: ['MIT'] }]) end + + it 'downloads packages from by using a custom `settings.xml`' do + runner.add_file('pom.xml', fixture_file_content('pom-public-gitlab-repository.xml')) + runner.add_file('my_settings.xml', fixture_file_content(' custom-maven-settings.xml')) + + report = runner.scan(env: { + 'LICENSE_FINDER_CLI_OPTS' => '--maven-options="-S my_settings.xml"' + }) + + expect(report).to match_schema(version: '2.0') + expect(report[:dependencies]).to match_array([{ name: 'mvn-spike', url: '', description: '', paths: ['.'], licenses: ['MIT'] }]) + end end end diff --git a/spec/support/fixture_file_helper.rb b/spec/support/fixture_file_helper.rb index c98b98a..fe11acd 100644 --- a/spec/support/fixture_file_helper.rb +++ b/spec/support/fixture_file_helper.rb @@ -1,5 +1,9 @@ module FixtureFileHelper def fixture_file_content(path) - IO.read(License::Management.root.join("spec/fixtures/#{path}")) + IO.read(fixture_file(path)) + end + + def fixture_file(path) + License::Management.root.join("spec/fixtures/#{path}") end end |
