From 8e46aa67ca5be04f5aae12a4eec63434ed0fefff Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 15 Oct 2019 16:31:02 -0600 Subject: This maps the hardcoded names to spdx ids The GitLab UI has a hardcoded list of license names that need to be mapped to the equivalent SPDX identifier. * https://gitlab.com/gitlab-org/gitlab/blob/5d760ac8b75c07a3c748485fe08130fcc9af2acf/ee/app/assets/javascripts/vue_shared/license_management/constants.js#L8-32 --- spec/license/management/report/v2_spec.rb | 43 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 16 ++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 spec/license/management/report/v2_spec.rb create mode 100644 spec/spec_helper.rb (limited to 'spec') diff --git a/spec/license/management/report/v2_spec.rb b/spec/license/management/report/v2_spec.rb new file mode 100644 index 0000000..766c08d --- /dev/null +++ b/spec/license/management/report/v2_spec.rb @@ -0,0 +1,43 @@ +RSpec.describe License::Management::Report::V2 do + describe "#to_h" do + { + 'AGPL-1.0' => 'AGPL-1.0', + 'AGPL-3.0' => 'AGPL-3.0', + 'Apache 2.0' => 'Apache-2.0', + 'Artistic-2.0' => 'Artistic-2.0', + 'BSD' => 'BSD-4-Clause', + 'CC0 1.0 Universal' => 'CC0-1.0', + 'CDDL-1.0' => 'CDDL-1.0', + 'CDDL-1.1' => 'CDDL-1.1', + 'EPL-1.0' => 'EPL-1.0', + 'EPL-2.0' => 'EPL-2.0', + 'GPLv2' => 'GPL-2.0', + 'GPLv3' => 'GPL-3.0', + 'ISC' => 'ISC', + 'LGPL' => 'LGPL-3.0-only', + 'LGPL-2.1' => 'LGPL-2.1', + 'MIT' => 'MIT', + 'Mozilla Public License 2.0' => 'MPL-2.0', + 'MS-PL' => 'MS-PL', + 'MS-RL' => 'MS-RL', + 'New BSD' => 'BSD-3-Clause', + 'Python Software Foundation License' => 'Python-2.0', + 'ruby' => 'Ruby', + 'Simplified BSD' => 'BSD-2-Clause', + 'WTFPL' => 'WTFPL', + 'Zlib' => 'Zlib' + }.each do |old_name, spdx_id| + context "when mapping the legacy license name #{old_name}" do + subject { described_class.new([dependency]) } + + let(:license) { LicenseFinder::License.new(short_name: old_name, matcher: LicenseFinder::License::NoneMatcher.new, url: nil) } + let(:dependency) { double(name: 'x', summary: '', description: '', homepage: '', licenses: [license]) } + let(:result) { subject.to_h } + + specify { expect(result[:version]).to eq('2.0') } + specify { expect(result[:licenses].count).to be(1) } + specify { expect(result[:licenses][0]['id']).to eq(spdx_id) } + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2282613 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,16 @@ +require 'license/management' + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + config.shared_context_metadata_behavior = :apply_to_host_groups + config.filter_run_when_matching :focus + config.disable_monkey_patching! + config.warnings = true + config.order = :random + Kernel.srand config.seed +end -- cgit v1.2.3