license_finder 2.1.0.rc4 → 2.1.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/CHANGELOG.rdoc +17 -0
- data/features/features/report/composite_spec.rb +13 -0
- data/features/features/report/diff_spec.rb +8 -8
- data/features/features/report/subproject_spec.rb +3 -3
- data/features/fixtures/nuget/{packages/Microsoft.AspNet.Mvc.4.0.30506.0 → .nuget}/.keep +0 -0
- data/lib/license_finder/cli/main.rb +1 -1
- data/lib/license_finder/configuration.rb +2 -1
- data/lib/license_finder/license/definitions.rb +21 -0
- data/lib/license_finder/license/templates/MPL2.txt +373 -0
- data/lib/license_finder/package.rb +4 -0
- data/lib/license_finder/package_manager.rb +2 -1
- data/lib/license_finder/package_managers/bower_package.rb +4 -0
- data/lib/license_finder/package_managers/bundler_package.rb +4 -0
- data/lib/license_finder/package_managers/cocoa_pods_package.rb +4 -0
- data/lib/license_finder/package_managers/go_dep.rb +7 -1
- data/lib/license_finder/package_managers/go_package.rb +8 -6
- data/lib/license_finder/package_managers/go_vendor.rb +56 -0
- data/lib/license_finder/package_managers/go_workspace.rb +49 -14
- data/lib/license_finder/package_managers/gradle.rb +1 -1
- data/lib/license_finder/package_managers/gradle_package.rb +4 -0
- data/lib/license_finder/package_managers/maven_package.rb +4 -0
- data/lib/license_finder/package_managers/merged_package.rb +4 -0
- data/lib/license_finder/package_managers/npm_package.rb +4 -0
- data/lib/license_finder/package_managers/nuget.rb +16 -3
- data/lib/license_finder/package_managers/nuget_package.rb +3 -0
- data/lib/license_finder/package_managers/pip_package.rb +4 -0
- data/lib/license_finder/package_managers/rebar_package.rb +3 -0
- data/lib/license_finder/reports/csv_report.rb +5 -1
- data/lib/license_finder/reports/merged_report.rb +2 -1
- data/lib/license_finder/version.rb +1 -1
- data/license_finder.gemspec +1 -0
- data/{features/fixtures/nuget/packages/NUnit.2.6.4 → spec/fixtures/all_pms/.nuget}/.keep +0 -0
- data/spec/lib/license_finder/cli/main_spec.rb +10 -0
- data/spec/lib/license_finder/configuration_spec.rb +1 -1
- data/spec/lib/license_finder/license/definitions_spec.rb +12 -0
- data/spec/lib/license_finder/package_managers/bower_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/go_dep_spec.rb +29 -0
- data/spec/lib/license_finder/package_managers/go_package_spec.rb +33 -0
- data/spec/lib/license_finder/package_managers/go_vendor_spec.rb +99 -0
- data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +186 -46
- data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/gradle_spec.rb +2 -1
- data/spec/lib/license_finder/package_managers/maven_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/merged_package_spec.rb +5 -1
- data/spec/lib/license_finder/package_managers/npm_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/nuget_package_spec.rb +9 -0
- data/spec/lib/license_finder/package_managers/nuget_spec.rb +41 -0
- data/spec/lib/license_finder/package_managers/pip_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/rebar_package_spec.rb +1 -0
- data/spec/lib/license_finder/reports/csv_report_spec.rb +6 -0
- metadata +24 -8
- data/features/fixtures/nuget/packages/Ninject.MVC4.3.2.1.0/.keep +0 -0
- data/features/fixtures/nuget/packages/repositories.config +0 -6
- data/spec/fixtures/all_pms/packages/.keep +0 -0
@@ -74,6 +74,18 @@ describe LicenseFinder::License, "MIT" do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
describe LicenseFinder::License, "MPL2" do
|
78
|
+
subject { described_class.find_by_name "MPL2" }
|
79
|
+
|
80
|
+
describe "#matches_text?" do
|
81
|
+
it "should return true if the text begins with 'The Mozilla Public License, version 2.0'" do
|
82
|
+
expect(subject).to be_matches_text "Mozilla Public License, version 2.0"
|
83
|
+
|
84
|
+
expect(subject).not_to be_matches_text "Something else\nMozilla Public License, version 2.0"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
77
89
|
describe LicenseFinder::License, "NewBSD" do
|
78
90
|
subject { described_class.find_by_name "NewBSD" }
|
79
91
|
|
@@ -23,6 +23,7 @@ module LicenseFinder
|
|
23
23
|
its(:groups) { should == [] } # TODO: does `bower list` output devDependencies? If so, put them in 'dev' group?
|
24
24
|
its(:children) { should == [] } # TODO: get dependencies from dependencies and devDependencies, like NPM
|
25
25
|
its(:install_path) { should eq "/path/to/thing" }
|
26
|
+
its(:package_manager) { should eq 'Bower' }
|
26
27
|
|
27
28
|
context "when package is NOT installed" do
|
28
29
|
subject do
|
@@ -57,6 +57,35 @@ module LicenseFinder
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
context 'when there are duplicate dependencies' do
|
61
|
+
let(:content) do
|
62
|
+
'{
|
63
|
+
"ImportPath": "github.com/foo/bar",
|
64
|
+
"GoVersion": "go1.3",
|
65
|
+
"Deps": [
|
66
|
+
{
|
67
|
+
"ImportPath": "github.com/foo/baz/sub1",
|
68
|
+
"Rev": "28838aae6e8158e3695cf90e2f0ed2498b68ee1d"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"ImportPath": "github.com/foo/baz/sub2",
|
72
|
+
"Rev": "28838aae6e8158e3695cf90e2f0ed2498b68ee1d"
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"ImportPath": "github.com/foo/baz/sub3",
|
76
|
+
"Rev": "28838aae6e8158e3695cf90e2f0ed2498b68ee1d"
|
77
|
+
}
|
78
|
+
]
|
79
|
+
}'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should return one dependency only' do
|
83
|
+
packages = subject.current_packages
|
84
|
+
expect(packages.map(&:name)).to eq(['github.com/foo/baz'])
|
85
|
+
expect(packages.map(&:version)).to eq(['28838aa'])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
60
89
|
context 'when dependencies are not vendored' do
|
61
90
|
before do
|
62
91
|
ENV['GOPATH'] = '/fake/go/path'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
describe GoPackage do
|
5
|
+
let(:options) {
|
6
|
+
{
|
7
|
+
'ImportPath' => 'github.com/pivotal/spec_name',
|
8
|
+
'Rev' => '4326c3435332d06b410a2672d28d1343c4059fae',
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:full_version) { true }
|
13
|
+
|
14
|
+
subject { described_class.from_dependency(options, Pathname.new('/Go/src'), full_version) }
|
15
|
+
|
16
|
+
its(:name) { should == 'github.com/pivotal/spec_name' }
|
17
|
+
its(:version) { should == '4326c3435332d06b410a2672d28d1343c4059fae' }
|
18
|
+
its(:install_path) { should == '/Go/src/github.com/pivotal/spec_name' }
|
19
|
+
its(:package_manager) { should == "Go" }
|
20
|
+
|
21
|
+
context 'when full version is set to false' do
|
22
|
+
let(:full_version) { false }
|
23
|
+
|
24
|
+
its(:version) { should == '4326c34' }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when the install path is set in the options' do
|
28
|
+
let(:options) { super().merge('InstallPath' => '/Go/vendor/src/github.com/pivotal/spec_name' ) }
|
29
|
+
|
30
|
+
its(:install_path) { should == '/Go/vendor/src/github.com/pivotal/spec_name' }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fakefs/spec_helpers'
|
3
|
+
|
4
|
+
module LicenseFinder
|
5
|
+
describe GoVendor do
|
6
|
+
include FakeFS::SpecHelpers
|
7
|
+
|
8
|
+
let(:project_path) { '/app' }
|
9
|
+
let(:options) { {} }
|
10
|
+
let(:logger) { double(:logger, active: nil) }
|
11
|
+
subject { GoVendor.new(options.merge(project_path: Pathname(project_path), logger: logger)) }
|
12
|
+
|
13
|
+
context 'when there are go files' do
|
14
|
+
before do
|
15
|
+
FileUtils.mkdir_p project_path
|
16
|
+
FileUtils.touch File.join(project_path, 'main.go')
|
17
|
+
FileUtils.mkdir_p File.join(project_path, 'vendor', 'github.com', 'foo', 'bar')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'detects the project as go vendor project' do
|
21
|
+
expect(subject.active?).to be true
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#current_packages' do
|
25
|
+
let(:go_deps) {
|
26
|
+
["github.com/foo/bar", true]
|
27
|
+
}
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(subject).to receive(:capture).with(%q[go list -f '{{join .Deps "\n"}}' ./...]).and_return(go_deps)
|
31
|
+
allow(subject).to receive(:capture).with(%q[git rev-list --max-count 1 HEAD]).and_return(["e0ff7ae205f\n", true])
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec.shared_examples 'current_packages' do |parameter|
|
35
|
+
it 'only returns the parent package' do
|
36
|
+
packages = subject.current_packages
|
37
|
+
expect(packages.count).to eq(1)
|
38
|
+
expect(packages.first.name).to eq('github.com/foo/bar')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
include_examples 'current_packages'
|
43
|
+
|
44
|
+
it 'uses the sha of the parent project as the dependency version' do
|
45
|
+
packages = subject.current_packages
|
46
|
+
expect(packages.first.version).to eq('vendored-e0ff7ae205f')
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when sub packages are being used' do
|
50
|
+
let(:go_deps) {
|
51
|
+
["github.com/foo/bar\ngithub.com/foo/bar/baz", true]
|
52
|
+
}
|
53
|
+
|
54
|
+
include_examples 'current_packages'
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when only sub packages are being used' do
|
58
|
+
let(:go_deps) {
|
59
|
+
["github.com/foo/bar/baz", true]
|
60
|
+
}
|
61
|
+
|
62
|
+
include_examples 'current_packages'
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when unvendored packages are being used' do
|
66
|
+
let(:go_deps) {
|
67
|
+
["github.com/foo/bar\ntext/template/parse", true]
|
68
|
+
}
|
69
|
+
|
70
|
+
include_examples 'current_packages'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when there are go files in subdirectories' do
|
76
|
+
before do
|
77
|
+
FileUtils.mkdir_p project_path
|
78
|
+
FileUtils.mkdir_p File.join(project_path, 'vendor', 'github.com', 'foo', 'bar')
|
79
|
+
FileUtils.touch File.join(project_path, 'vendor', 'github.com', 'foo', 'bar', 'main.go')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'detects the project as go vendor project' do
|
83
|
+
expect(subject.active?).to be true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'if no go files exist' do
|
88
|
+
let(:project_path) { '/ruby_app' }
|
89
|
+
|
90
|
+
before do
|
91
|
+
FileUtils.mkdir_p File.join(project_path, 'vendor')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should not mark the project active' do
|
95
|
+
expect(subject.active?).to be false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -4,35 +4,110 @@ module LicenseFinder
|
|
4
4
|
describe GoWorkspace do
|
5
5
|
let(:options) { {} }
|
6
6
|
let(:logger) { double(:logger, active: nil) }
|
7
|
-
|
7
|
+
let(:project_path) { '/Users/pivotal/workspace/loggregator'}
|
8
|
+
subject { GoWorkspace.new(options.merge(project_path: Pathname(project_path), logger: logger)) }
|
9
|
+
|
10
|
+
describe '#go_list' do
|
11
|
+
|
12
|
+
let(:go_list_output) {
|
13
|
+
<<HERE
|
14
|
+
encoding/json
|
15
|
+
github.com/onsi/ginkgo
|
16
|
+
HERE
|
17
|
+
}
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(Dir).to receive(:chdir).with(Pathname.new project_path) { |&b| b.call() }
|
21
|
+
allow(FileTest).to receive(:exist?).and_return(false)
|
22
|
+
allow(FileTest).to receive(:exist?).with(File.join(project_path, '.envrc')).and_return(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'changes the directory' do
|
26
|
+
subject.send(:go_list)
|
27
|
+
|
28
|
+
expect(Dir).to have_received(:chdir)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns the skip the standard libs and return lines of the output' do
|
32
|
+
allow(subject).to receive(:capture).with('go list -f \'{{join .Deps "\n"}}\' ./...').and_return([go_list_output, true])
|
33
|
+
packages = subject.send(:go_list)
|
34
|
+
expect(packages.count).to eq(1)
|
35
|
+
expect(packages.first).to eq('github.com/onsi/ginkgo')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'sets gopath to the envrc path' do
|
39
|
+
allow(subject).to receive(:capture).with('go list -f \'{{join .Deps "\n"}}\' ./...') {
|
40
|
+
expect(ENV['GOPATH']).to be_nil
|
41
|
+
['', true]
|
42
|
+
}
|
43
|
+
|
44
|
+
subject.send(:go_list)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#git_modules' do
|
49
|
+
before do
|
50
|
+
allow(FileTest).to receive(:exist?).and_return(false)
|
51
|
+
allow(FileTest).to receive(:exist?).with('/Users/pivotal/workspace/loggregator/.envrc').and_return(true)
|
52
|
+
allow(Dir).to receive(:chdir).with(Pathname.new '/Users/pivotal/workspace/loggregator') { |&b| b.call() }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'if git submodule status fails' do
|
56
|
+
before do
|
57
|
+
allow(subject).to receive(:capture).with('git submodule status').and_return(['', false])
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should raise an exception' do
|
61
|
+
expect { subject.send(:git_modules) }.to raise_exception(/git submodule status failed/)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'if git submodule status succeeds' do
|
66
|
+
let(:git_submodule_status_output) {
|
67
|
+
<<HERE
|
68
|
+
1993eafbef57be29ee8f5eb9d26a22f20ff3c207 src/github.com/GaryBoone/GoStats (heads/master)
|
69
|
+
55eb11d21d2a31a3cc93838241d04800f52e823d src/github.com/Sirupsen/logrus (v0.7.3)
|
70
|
+
HERE
|
71
|
+
}
|
72
|
+
|
73
|
+
before do
|
74
|
+
allow(subject).to receive(:capture).with('git submodule status').and_return([git_submodule_status_output, true])
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should return the filtered submodules' do
|
78
|
+
submodules = subject.send(:git_modules)
|
79
|
+
expect(submodules.count).to eq(2)
|
80
|
+
expect(submodules.first.install_path).to eq('/Users/pivotal/workspace/loggregator/src/github.com/GaryBoone/GoStats')
|
81
|
+
expect(submodules.first.revision).to eq('1993eafbef57be29ee8f5eb9d26a22f20ff3c207')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
8
85
|
|
9
86
|
describe '#current_packages' do
|
10
|
-
let(:
|
11
|
-
|
12
|
-
_/Users/pivotal/workspace/loggregator/src/bitbucket.org/kardianos/osext/something
|
13
|
-
_/Users/pivotal/workspace/loggregator/src/deaagent
|
14
|
-
_/Users/pivotal/workspace/loggregator/src/deaagent/deaagent
|
15
|
-
_/Users/pivotal/workspace/loggregator/src/deaagent/domain
|
16
|
-
_/Users/pivotal/workspace/loggregator/src/doppler
|
17
|
-
_/Users/pivotal/workspace/loggregator/src/doppler/config
|
18
|
-
_/Users/pivotal/workspace/loggregator/src/doppler/groupedsinks
|
19
|
-
_/Users/pivotal/workspace/loggregator/src/doppler/groupedsinks/firehose_group
|
20
|
-
_/Users/pivotal/workspace/loggregator/src/doppler/groupedsinks/sink_wrapper'
|
87
|
+
let(:git_modules_output) {
|
88
|
+
[GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/src/bitbucket.org/kardianos/osext", "b8a35001b773c267e")]
|
21
89
|
}
|
22
90
|
|
23
|
-
let(:
|
24
|
-
|
91
|
+
let(:go_list_output) {
|
92
|
+
[
|
93
|
+
"bitbucket.org/kardianos/osext",
|
94
|
+
"bitbucket.org/kardianos/osext/foo",
|
95
|
+
]
|
25
96
|
}
|
26
97
|
|
98
|
+
|
27
99
|
before do
|
100
|
+
allow(FileTest).to receive(:exist?).and_return(true)
|
101
|
+
|
28
102
|
allow(Dir).to receive(:chdir).with(Pathname('/Users/pivotal/workspace/loggregator')) { |&block| block.call }
|
29
|
-
allow(subject).to receive(:
|
30
|
-
allow(subject).to receive(:
|
103
|
+
allow(subject).to receive(:go_list).and_return(go_list_output)
|
104
|
+
allow(subject).to receive(:git_modules).and_return(git_modules_output)
|
31
105
|
end
|
32
106
|
|
33
107
|
describe 'should return an array of go packages' do
|
34
108
|
it 'provides package names' do
|
35
109
|
packages = subject.current_packages
|
110
|
+
expect(packages.count).to eq(1)
|
36
111
|
first_package = packages.first
|
37
112
|
expect(first_package.name).to eq 'bitbucket.org/kardianos/osext'
|
38
113
|
expect(first_package.version).to eq 'b8a3500'
|
@@ -45,53 +120,118 @@ module LicenseFinder
|
|
45
120
|
expect(packages.count).to eq(1)
|
46
121
|
end
|
47
122
|
|
48
|
-
context 'if git submodule status fails' do
|
49
|
-
before do
|
50
|
-
allow(subject).to receive(:capture).with('git submodule status').and_return(['', false])
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should raise an exception' do
|
54
|
-
expect { subject.current_packages }.to raise_exception(/git submodule status failed/)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
123
|
context 'when requesting the full version' do
|
59
124
|
let(:options) { { go_full_version:true } }
|
60
125
|
it 'list the dependencies with full version' do
|
61
126
|
expect(subject.current_packages.map(&:version)).to eq ["b8a35001b773c267e"]
|
62
127
|
end
|
63
128
|
end
|
64
|
-
end
|
65
129
|
|
66
|
-
|
67
|
-
|
68
|
-
|
130
|
+
context 'when the deps are in a vendor directory' do
|
131
|
+
let(:git_modules_output) {
|
132
|
+
[GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/vendor/src/bitbucket.org/kardianos/osext", "b8a35001b773c267e")]
|
133
|
+
}
|
134
|
+
|
135
|
+
it 'reports the right import path' do
|
136
|
+
expect(subject.current_packages.map(&:name)).to include('bitbucket.org/kardianos/osext')
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'reports the right install path' do
|
140
|
+
expect(subject.current_packages.map(&:install_path)).to include('/Users/pivotal/workspace/loggregator/vendor/src/bitbucket.org/kardianos/osext')
|
141
|
+
end
|
69
142
|
end
|
70
|
-
end
|
71
143
|
|
72
|
-
|
73
|
-
|
144
|
+
context 'when only the subpackage is being used' do
|
145
|
+
let(:go_list_output) {
|
146
|
+
[
|
147
|
+
"bitbucket.org/kardianos/osext/foo",
|
148
|
+
]
|
149
|
+
}
|
74
150
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
151
|
+
it 'returns the top level repo name as the import path' do
|
152
|
+
packages = subject.current_packages
|
153
|
+
expect(packages.map(&:name)).to eq(['bitbucket.org/kardianos/osext'])
|
154
|
+
end
|
79
155
|
end
|
80
156
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
157
|
+
context 'when only the subpackage is being used' do
|
158
|
+
let(:git_modules_output) {
|
159
|
+
[GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/vendor/src/github.com/onsi/foo", "e762c377b10053a8b"),
|
160
|
+
GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/vendor/src/github.com/onsi/foobar", "b8a35001b773c267e")]
|
161
|
+
}
|
162
|
+
|
163
|
+
let(:go_list_output) {
|
164
|
+
[
|
165
|
+
"github.com/onsi/foo",
|
166
|
+
"github.com/onsi/foobar",
|
167
|
+
]
|
168
|
+
}
|
169
|
+
|
170
|
+
it 'returns the top level repo name as the import path' do
|
171
|
+
packages = subject.current_packages
|
172
|
+
expect(packages.map(&:name)).to eq(['github.com/onsi/foo', 'github.com/onsi/foobar'])
|
173
|
+
end
|
85
174
|
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#package_path' do
|
179
|
+
before do
|
180
|
+
allow(FileTest).to receive(:exist?).and_return(true)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'returns the package_path' do
|
184
|
+
expect(subject.package_path).to eq Pathname('/Users/pivotal/workspace/loggregator')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#active?' do
|
189
|
+
let(:envrc) { '/Users/pivotal/workspace/loggregator/.envrc' }
|
190
|
+
|
191
|
+
before do
|
192
|
+
allow(FileTest).to receive(:exist?).and_return(false)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'returns true when .envrc contains GOPATH' do
|
196
|
+
allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
|
197
|
+
allow(IO).to receive(:read).with(Pathname(envrc)).and_return('export GOPATH=/foo/bar')
|
198
|
+
expect(subject.active?).to eq(true)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'returns false when .envrc does not contain GOPATH' do
|
202
|
+
allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
|
203
|
+
allow(IO).to receive(:read).with(Pathname(envrc)).and_return('this is not an envrc file')
|
204
|
+
expect(subject.active?).to eq(false)
|
205
|
+
end
|
86
206
|
|
87
|
-
|
88
|
-
|
207
|
+
it 'returns false when .envrc does not exist' do
|
208
|
+
expect(subject.active?).to eq(false)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'logs the active state' do
|
212
|
+
expect(logger).to receive(:active)
|
213
|
+
subject.active?
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'when Godep is present' do
|
217
|
+
let(:godeps) { '/Users/pivotal/workspace/loggregator/Godeps/Godeps.json' }
|
218
|
+
|
219
|
+
it 'should prefer Godeps over go_workspace' do
|
220
|
+
allow(FileTest).to receive(:exist?).with(Pathname(godeps)).and_return(true)
|
89
221
|
expect(subject.active?).to eq(false)
|
90
222
|
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context 'when .envrc is present in a parent directory' do
|
226
|
+
subject {
|
227
|
+
GoWorkspace.new(options.merge(project_path: Pathname('/Users/pivotal/workspace/loggregator/src/github.com/foo/bar'),
|
228
|
+
logger: logger))
|
229
|
+
}
|
91
230
|
|
92
|
-
it '
|
93
|
-
|
94
|
-
|
231
|
+
it 'returns true' do
|
232
|
+
allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
|
233
|
+
allow(IO).to receive(:read).with(Pathname(envrc)).and_return('export GOPATH=/foo/bar')
|
234
|
+
expect(subject.active?).to be true
|
95
235
|
end
|
96
236
|
end
|
97
237
|
end
|