-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_relative '../../support/feature_helper' | ||
|
||
describe 'Go Modules Dependencies' do | ||
let(:go_developer) { LicenseFinder::TestingDSL::User.new } | ||
|
||
specify 'are shown in reports for a project' do | ||
LicenseFinder::TestingDSL::GoModulesProject.create | ||
go_developer.run_license_finder('go_modules') | ||
|
||
expect(go_developer).to be_seeing_line 'gopkg.in/check.v1, v0.0.0-20161208181325-20d25e280405, "Apache 2.0, MIT"' | ||
expect(go_developer).to be_seeing_line 'gopkg.in/yaml.v2, v2.2.1, "Apache 2.0, MIT"' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module foo | ||
|
||
require gopkg.in/yaml.v2 v2.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= | ||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package foo | ||
|
||
import ( | ||
"gopkg.in/yaml.v2" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module LicenseFinder | ||
class GoModules < PackageManager | ||
PACKAGES_FILE = 'go.sum'.freeze | ||
|
||
class << self | ||
def takes_priority_over | ||
Go15VendorExperiment | ||
end | ||
|
||
def prepare_command | ||
'go mod vendor' | ||
end | ||
end | ||
|
||
def active? | ||
sum_files? | ||
end | ||
|
||
def current_packages | ||
sum_file_paths.uniq.map do |file_path| | ||
read_sum(file_path) | ||
end.flatten | ||
end | ||
|
||
private | ||
|
||
def sum_files? | ||
sum_file_paths.any? | ||
end | ||
|
||
def sum_file_paths | ||
Dir[project_path.join(PACKAGES_FILE)] | ||
end | ||
|
||
def read_sum(file_path) | ||
contents = File.read(file_path) | ||
contents.each_line.map do |line| | ||
line.include?('go.mod') ? nil : read_package(file_path, line) | ||
end.compact | ||
end | ||
|
||
def read_package(file_path, line) | ||
parts = line.split(' ') | ||
install_path = File.dirname(file_path) | ||
|
||
name = parts[0] | ||
version = parts[1] | ||
|
||
Package.new(name, version, install_path: install_path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= | ||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
60 changes: 60 additions & 0 deletions
60
spec/lib/license_finder/package_managers/go_modules_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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" } | ||
|
||
subject { GoModules.new(project_path: Pathname(src_path), logger: double(:logger, active: nil)) } | ||
|
||
describe '#current_packages' do | ||
before do | ||
FakeFS.activate! | ||
end | ||
|
||
after do | ||
FakeFS.deactivate! | ||
end | ||
|
||
let(:src_path) { '/workspace/code' } | ||
let(:sum_path) { "#{src_path}/go.sum" } | ||
|
||
let(:content) do | ||
FakeFS.without do | ||
fixture_from('go.sum') | ||
end | ||
end | ||
|
||
it 'finds all the packages all go.sum files' do | ||
FileUtils.mkdir_p(vendor_path) | ||
File.write(sum_path, content) | ||
|
||
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 | ||
end | ||
|
||
describe '.prepare_command' do | ||
it 'returns the correct package management command' do | ||
expect(described_class.prepare_command).to eq('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 |