-
Notifications
You must be signed in to change notification settings - Fork 335
/
go_modules_spec.rb
71 lines (55 loc) · 2.17 KB
/
go_modules_spec.rb
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
# frozen_string_literal: true
require 'spec_helper'
require 'fakefs/spec_helpers'
module LicenseFinder
describe GoModules do
it_behaves_like 'a PackageManager'
let(:src_path) { '/workspace/code' }
let(:sum_path) { "#{src_path}/go.sum" }
let(:vendor_path) { "#{src_path}/vendor" }
let(:go_list_string) do
"foo,,/workspace/code/\ngopkg.in/check.v1,v0.0.0-20161208181325-20d25e280405,"\
"/workspace/LicenseFinder/features/fixtures/go_modules/vendor/gopkg.in/check.v1\n"\
'gopkg.in/yaml.v2,v2.2.1,/workspace/LicenseFinder/features/fixtures/go_modules/vendor/gopkg.in/yaml.v2'
end
subject { GoModules.new(project_path: Pathname(src_path), logger: double(:logger, active: nil)) }
describe '#current_packages' do
before do
FakeFS.activate!
FileUtils.mkdir_p(vendor_path)
File.write(sum_path, content)
allow(SharedHelpers::Cmd).to receive(:run).with("GO111MODULE=on go list -m -mod=vendor -f '{{.Path}},{{.Version}},{{.Dir}}' all").and_return(go_list_string)
end
after do
FakeFS.deactivate!
end
let(:content) do
FakeFS.without do
fixture_from('go.sum')
end
end
it 'finds all the packages all go.sum files' do
packages = subject.current_packages
expect(packages.length).to eq 2
expect(packages.first.name).to eq 'gopkg.in/check.v1'
expect(packages.first.version).to eq 'v0.0.0-20161208181325-20d25e280405'
expect(packages.last.name).to eq 'gopkg.in/yaml.v2'
expect(packages.last.version).to eq 'v2.2.1'
end
it 'list packages as Go packages' do
packages = subject.current_packages
expect(packages.first.package_manager).to eq 'Go'
end
end
describe '.prepare_command' do
it 'returns the correct package management command' do
expect(described_class.prepare_command).to eq('GO111MODULE=on go mod tidy && GO111MODULE=on go mod vendor')
end
end
describe '.takes_priority_over' do
it 'returns the package manager it takes priority over' do
expect(described_class.takes_priority_over).to eq(Go15VendorExperiment)
end
end
end
end