summaryrefslogtreecommitdiff
path: root/spec/integration/rust/cargo_spec.rb
blob: 440d3ac161e78525dc6d10b8c064c822afdf5250 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe "cargo" do
  subject { runner.scan(env: env) }

  let(:env) { {} }

  before do
    install_dir = '/opt/asdf/installs/rust'
    system("rm -r #{install_dir}") if Dir.exist?(install_dir)
  end

  include_examples "each report version", "rust", "cargo", "1a7c2572"

  context "when scanning a cargo project" do
    before do
      runner.mount(dir: fixture_file('rust/cargo/hello_world'))
    end

    specify { expect(subject).to match_schema }

    specify do
      expect(subject.dependency_names).to match_array(%w[libc time])
    end

    specify { expect(subject.licenses_for('libc')).to match_array(['MIT', 'Apache-2.0']) }
    specify { expect(subject.licenses_for('time')).to match_array(['Apache-2.0', 'MIT']) }
  end

  context "when fetching dependencies from a custom registry" do
    before do
      runner.mount(dir: fixture_file('rust/cargo/custom-tls'))
    end

    context "when the CA certificate is provided" do
      let(:env) { { 'ADDITIONAL_CA_CERT_BUNDLE' => x509_certificate.read } }

      specify do
        expect(subject).to match_schema
        expect(subject.dependency_names).to match_array(['libc'])
        expect(subject.licenses_for('libc')).to match_array(['MIT', 'Apache-2.0'])
      end
    end

    context "when the CA certificate is NOT provided" do
      let(:env) { {} }

      specify { expect(subject).to match_schema }
    end
  end

  context "when scanning a project with dev dependencies" do
    before do
      runner.mount(dir: fixture_file('rust/cargo/dev-dependencies'))
    end

    it 'excludes them from the report' do
      expect(subject).to match_schema
      expect(subject.dependency_names).to include('diesel')
      expect(subject.dependency_names).not_to include('pretty_assertions')
    end
  end

  context "when scanning https://gitlab.com/inko-lang/inko.git" do
    let(:env) { { 'LICENSE_FINDER_CLI_OPTS' => '--aggregate-paths=vm compiler' } }

    before do
      runner.clone('https://gitlab.com/inko-lang/inko.git')
    end

    specify { expect(subject).to match_schema }
    specify { expect { subject }.to perform_under(60).sec.warmup(0).times }
  end
end