license_finder 3.0.4 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +56 -0
  3. data/CHANGELOG.md +29 -2
  4. data/CONTRIBUTING.md +5 -1
  5. data/Dockerfile +33 -10
  6. data/Gemfile +2 -2
  7. data/README.md +27 -5
  8. data/Rakefile +15 -21
  9. data/ci/pipelines/pipeline.yml.erb +40 -6
  10. data/ci/pipelines/release.yml +11 -5
  11. data/ci/scripts/containerize-tests.sh +16 -0
  12. data/ci/scripts/run-rubocop.sh +8 -0
  13. data/ci/scripts/run-tests.sh +22 -0
  14. data/ci/scripts/test.ps1 +81 -0
  15. data/ci/tasks/build-windows.yml +6 -0
  16. data/ci/tasks/build.yml +2 -2
  17. data/ci/tasks/rubocop.yml +13 -0
  18. data/features/features/cli/cli_spec.rb +8 -8
  19. data/features/features/configure/add_dependencies_spec.rb +7 -7
  20. data/features/features/configure/approve_dependencies_spec.rb +15 -15
  21. data/features/features/configure/assign_licenses_spec.rb +4 -4
  22. data/features/features/configure/blacklist_licenses_spec.rb +3 -3
  23. data/features/features/configure/ignore_dependencies_spec.rb +3 -3
  24. data/features/features/configure/ignore_groups_spec.rb +4 -4
  25. data/features/features/configure/name_project_spec.rb +4 -4
  26. data/features/features/configure/set_project_path_spec.rb +2 -2
  27. data/features/features/configure/whitelist_licenses_spec.rb +4 -4
  28. data/features/features/package_managers/bower_spec.rb +3 -3
  29. data/features/features/package_managers/carthage_spec.rb +14 -0
  30. data/features/features/package_managers/cocoapods_spec.rb +3 -3
  31. data/features/features/package_managers/conan_spec.rb +11 -0
  32. data/features/features/package_managers/dep_spec.rb +15 -0
  33. data/features/features/package_managers/glide_spec.rb +14 -0
  34. data/features/features/package_managers/govendor_spec.rb +15 -0
  35. data/features/features/package_managers/gradle_spec.rb +1 -1
  36. data/features/features/package_managers/gvt_spec.rb +14 -0
  37. data/features/features/package_managers/maven_spec.rb +2 -3
  38. data/features/features/package_managers/mix_spec.rb +16 -0
  39. data/features/features/package_managers/npm_spec.rb +3 -3
  40. data/features/features/package_managers/nuget_spec.rb +4 -4
  41. data/features/features/package_managers/pip_spec.rb +2 -2
  42. data/features/features/package_managers/rebar_spec.rb +3 -3
  43. data/features/features/package_managers/yarn_spec.rb +14 -0
  44. data/features/features/report/composite_spec.rb +1 -1
  45. data/features/features/report/csv_spec.rb +3 -3
  46. data/features/features/report/diff_spec.rb +20 -10
  47. data/features/features/report/html_spec.rb +10 -10
  48. data/features/features/report/subproject_spec.rb +15 -4
  49. data/features/fixtures/Cartfile +1 -0
  50. data/features/fixtures/Podfile +1 -1
  51. data/features/fixtures/alternate-build-file-gradle/build-alt.gradle +5 -15
  52. data/features/fixtures/build.gradle +5 -15
  53. data/features/fixtures/conanfile.txt +11 -0
  54. data/features/fixtures/file-based-libs-gradle/build.gradle +5 -7
  55. data/features/fixtures/gopath_dep/src/foo-dep/Gopkg.lock +9 -0
  56. data/features/fixtures/gopath_dep/src/foo-dep/Gopkg.toml +7 -0
  57. data/features/fixtures/gopath_dep/src/foo-dep/bar/bar.go +10 -0
  58. data/features/fixtures/gopath_dep/src/foo-dep/foo.go +7 -0
  59. data/features/fixtures/gopath_glide/src/glide.lock +9 -0
  60. data/features/fixtures/gopath_glide/src/glide.yaml +6 -0
  61. data/features/fixtures/gopath_govendor/src/vendor/vendor.json +19 -0
  62. data/features/fixtures/gopath_gvt/src/vendor/manifest +22 -0
  63. data/features/fixtures/gradle-wrapper/build.gradle +5 -15
  64. data/features/fixtures/gradle-wrapper/gradlew +6 -1
  65. data/features/fixtures/gradle-wrapper/gradlew.bat +9 -1
  66. data/features/fixtures/mix.exs +22 -0
  67. data/features/fixtures/multi-module-gradle/build.gradle +7 -15
  68. data/features/fixtures/single-module-gradle/build.gradle +5 -15
  69. data/features/support/testing_dsl.rb +155 -43
  70. data/lib/license_finder.rb +4 -3
  71. data/lib/license_finder/cli.rb +0 -3
  72. data/lib/license_finder/cli/approvals.rb +3 -3
  73. data/lib/license_finder/cli/base.rb +11 -8
  74. data/lib/license_finder/cli/blacklist.rb +7 -7
  75. data/lib/license_finder/cli/dependencies.rb +8 -8
  76. data/lib/license_finder/cli/ignored_dependencies.rb +4 -4
  77. data/lib/license_finder/cli/ignored_groups.rb +4 -4
  78. data/lib/license_finder/cli/licenses.rb +2 -2
  79. data/lib/license_finder/cli/main.rb +59 -39
  80. data/lib/license_finder/cli/makes_decisions.rb +2 -2
  81. data/lib/license_finder/cli/patched_thor.rb +6 -7
  82. data/lib/license_finder/cli/project_name.rb +5 -6
  83. data/lib/license_finder/cli/whitelist.rb +7 -7
  84. data/lib/license_finder/configuration.rb +15 -4
  85. data/lib/license_finder/core.rb +20 -4
  86. data/lib/license_finder/decision_applier.rb +0 -1
  87. data/lib/license_finder/decisions.rb +12 -14
  88. data/lib/license_finder/diff.rb +33 -31
  89. data/lib/license_finder/license.rb +13 -9
  90. data/lib/license_finder/license/definitions.rb +55 -55
  91. data/lib/license_finder/license/none_matcher.rb +1 -1
  92. data/lib/license_finder/license/template.rb +1 -1
  93. data/lib/license_finder/license/text.rb +0 -1
  94. data/lib/license_finder/license_aggregator.rb +1 -0
  95. data/lib/license_finder/logger.rb +18 -61
  96. data/lib/license_finder/package.rb +25 -11
  97. data/lib/license_finder/package_delta.rb +3 -6
  98. data/lib/license_finder/package_manager.rb +77 -34
  99. data/lib/license_finder/package_managers/bower.rb +8 -8
  100. data/lib/license_finder/package_managers/bower_package.rb +12 -12
  101. data/lib/license_finder/package_managers/bundler.rb +21 -9
  102. data/lib/license_finder/package_managers/bundler_package.rb +1 -1
  103. data/lib/license_finder/package_managers/carthage.rb +66 -0
  104. data/lib/license_finder/package_managers/carthage_package.rb +16 -0
  105. data/lib/license_finder/package_managers/cocoa_pods.rb +13 -13
  106. data/lib/license_finder/package_managers/cocoa_pods_package.rb +1 -1
  107. data/lib/license_finder/package_managers/conan.rb +26 -0
  108. data/lib/license_finder/package_managers/conan_info_parser.rb +74 -0
  109. data/lib/license_finder/package_managers/conan_package.rb +17 -0
  110. data/lib/license_finder/package_managers/dep.rb +33 -0
  111. data/lib/license_finder/package_managers/glide.rb +30 -0
  112. data/lib/license_finder/package_managers/{go_vendor.rb → go_15vendorexperiment.rb} +19 -24
  113. data/lib/license_finder/package_managers/go_dep.rb +15 -12
  114. data/lib/license_finder/package_managers/go_package.rb +15 -13
  115. data/lib/license_finder/package_managers/go_workspace.rb +39 -34
  116. data/lib/license_finder/package_managers/govendor.rb +32 -0
  117. data/lib/license_finder/package_managers/gradle.rb +16 -16
  118. data/lib/license_finder/package_managers/gradle_package.rb +8 -8
  119. data/lib/license_finder/package_managers/gvt.rb +61 -0
  120. data/lib/license_finder/package_managers/maven.rb +17 -18
  121. data/lib/license_finder/package_managers/maven_package.rb +4 -6
  122. data/lib/license_finder/package_managers/merged_package.rb +25 -2
  123. data/lib/license_finder/package_managers/mix.rb +51 -0
  124. data/lib/license_finder/package_managers/mix_package.rb +7 -0
  125. data/lib/license_finder/package_managers/npm.rb +8 -32
  126. data/lib/license_finder/package_managers/npm_package.rb +51 -48
  127. data/lib/license_finder/package_managers/nuget.rb +30 -40
  128. data/lib/license_finder/package_managers/pip.rb +11 -11
  129. data/lib/license_finder/package_managers/pip_package.rb +8 -8
  130. data/lib/license_finder/package_managers/rebar.rb +11 -11
  131. data/lib/license_finder/package_managers/yarn.rb +62 -0
  132. data/lib/license_finder/packages/activation.rb +2 -2
  133. data/lib/license_finder/packages/license_files.rb +6 -6
  134. data/lib/license_finder/packages/licensing.rb +8 -10
  135. data/lib/license_finder/packages/manual_package.rb +2 -2
  136. data/lib/license_finder/project_finder.rb +6 -5
  137. data/lib/license_finder/report.rb +1 -0
  138. data/lib/license_finder/reports/csv_report.rb +4 -4
  139. data/lib/license_finder/reports/diff_report.rb +2 -2
  140. data/lib/license_finder/reports/erb_report.rb +2 -4
  141. data/lib/license_finder/reports/html_report.rb +2 -2
  142. data/lib/license_finder/reports/markdown_report.rb +1 -1
  143. data/lib/license_finder/reports/merged_report.rb +1 -1
  144. data/lib/license_finder/reports/text_report.rb +3 -5
  145. data/lib/license_finder/shared_helpers/cmd.rb +11 -0
  146. data/lib/license_finder/version.rb +1 -1
  147. data/license_finder-2.1.2.gem +0 -0
  148. data/license_finder.gemspec +38 -38
  149. metadata +84 -118
  150. data/ci/scripts/test.sh +0 -26
  151. data/ci/tasks/create-source-archives.yml +0 -23
  152. data/spec/dummy_app/Gemfile +0 -6
  153. data/spec/fixtures/all_pms/.envrc +0 -1
  154. data/spec/fixtures/all_pms/.nuget/.keep +0 -0
  155. data/spec/fixtures/all_pms/Gemfile +0 -0
  156. data/spec/fixtures/all_pms/Godeps/Godeps.json +0 -0
  157. data/spec/fixtures/all_pms/Podfile +0 -0
  158. data/spec/fixtures/all_pms/bower.json +0 -0
  159. data/spec/fixtures/all_pms/build.gradle +0 -0
  160. data/spec/fixtures/all_pms/package.json +0 -0
  161. data/spec/fixtures/all_pms/pom.xml +0 -0
  162. data/spec/fixtures/all_pms/rebar.config +0 -0
  163. data/spec/fixtures/all_pms/requirements.txt +0 -0
  164. data/spec/fixtures/all_pms/vendor/.gitkeep +0 -0
  165. data/spec/fixtures/composite/Gemfile +0 -0
  166. data/spec/fixtures/composite/nested_project/.envrc +0 -8
  167. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Godeps.json +0 -16
  168. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Readme +0 -5
  169. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/foo.go +0 -6
  170. data/spec/fixtures/composite/not_a_project/DONTREADME.md +0 -0
  171. data/spec/fixtures/composite/project1/Gemfile +0 -0
  172. data/spec/fixtures/composite/project2/package.json +0 -0
  173. data/spec/fixtures/config/license_finder.yml +0 -5
  174. data/spec/fixtures/license_directory/COPYING +0 -1
  175. data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -1
  176. data/spec/fixtures/license_directory/LICENSE/lib/unrelated.txt +0 -2
  177. data/spec/fixtures/license_names/COPYING.txt +0 -1
  178. data/spec/fixtures/license_names/LICENSE +0 -1
  179. data/spec/fixtures/license_names/Licence.rdoc +0 -1
  180. data/spec/fixtures/license_names/Mit-License +0 -1
  181. data/spec/fixtures/license_names/README.rdoc +0 -1
  182. data/spec/fixtures/nested_gem/vendor/LICENSE +0 -1
  183. data/spec/fixtures/npm-circular-dependencies/npm-list.json +0 -5339
  184. data/spec/fixtures/npm-circular-dependencies/package.json +0 -5
  185. data/spec/fixtures/npm-circular-licenses/npm-list.json +0 -7597
  186. data/spec/fixtures/npm-circular-licenses/package.json +0 -23
  187. data/spec/fixtures/npm-licenses-string/npm-list.json +0 -7597
  188. data/spec/fixtures/npm-licenses-string/package.json +0 -23
  189. data/spec/fixtures/npm-recursive-dependencies/npm-list.json +0 -5158
  190. data/spec/fixtures/npm-recursive-dependencies/package.json +0 -15
  191. data/spec/fixtures/npm-stack-too-deep/npm-list.json +0 -13464
  192. data/spec/fixtures/npm-stack-too-deep/package.json +0 -5
  193. data/spec/fixtures/utf8_gem/README +0 -210
  194. data/spec/lib/license_finder/cli/approvals_spec.rb +0 -71
  195. data/spec/lib/license_finder/cli/blacklist_spec.rb +0 -58
  196. data/spec/lib/license_finder/cli/dependencies_spec.rb +0 -73
  197. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +0 -47
  198. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +0 -40
  199. data/spec/lib/license_finder/cli/licenses_spec.rb +0 -60
  200. data/spec/lib/license_finder/cli/main_spec.rb +0 -243
  201. data/spec/lib/license_finder/cli/project_name_spec.rb +0 -40
  202. data/spec/lib/license_finder/cli/whitelist_spec.rb +0 -58
  203. data/spec/lib/license_finder/configuration_spec.rb +0 -115
  204. data/spec/lib/license_finder/core_spec.rb +0 -54
  205. data/spec/lib/license_finder/decision_applier_spec.rb +0 -219
  206. data/spec/lib/license_finder/decisions_spec.rb +0 -408
  207. data/spec/lib/license_finder/diff_spec.rb +0 -129
  208. data/spec/lib/license_finder/license/definitions_spec.rb +0 -177
  209. data/spec/lib/license_finder/license_aggregator_spec.rb +0 -61
  210. data/spec/lib/license_finder/license_spec.rb +0 -106
  211. data/spec/lib/license_finder/package_delta_spec.rb +0 -18
  212. data/spec/lib/license_finder/package_manager_spec.rb +0 -62
  213. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +0 -71
  214. data/spec/lib/license_finder/package_managers/bower_spec.rb +0 -39
  215. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +0 -35
  216. data/spec/lib/license_finder/package_managers/bundler_spec.rb +0 -56
  217. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +0 -48
  218. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +0 -59
  219. data/spec/lib/license_finder/package_managers/go_dep_spec.rb +0 -126
  220. data/spec/lib/license_finder/package_managers/go_package_spec.rb +0 -33
  221. data/spec/lib/license_finder/package_managers/go_vendor_spec.rb +0 -144
  222. data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +0 -286
  223. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +0 -80
  224. data/spec/lib/license_finder/package_managers/gradle_spec.rb +0 -180
  225. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +0 -63
  226. data/spec/lib/license_finder/package_managers/maven_spec.rb +0 -128
  227. data/spec/lib/license_finder/package_managers/merged_package_spec.rb +0 -60
  228. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +0 -57
  229. data/spec/lib/license_finder/package_managers/npm_spec.rb +0 -253
  230. data/spec/lib/license_finder/package_managers/nuget_package_spec.rb +0 -9
  231. data/spec/lib/license_finder/package_managers/nuget_spec.rb +0 -157
  232. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +0 -87
  233. data/spec/lib/license_finder/package_managers/pip_spec.rb +0 -47
  234. data/spec/lib/license_finder/package_managers/rebar_package_spec.rb +0 -24
  235. data/spec/lib/license_finder/package_managers/rebar_spec.rb +0 -50
  236. data/spec/lib/license_finder/package_spec.rb +0 -179
  237. data/spec/lib/license_finder/packages/activation_spec.rb +0 -41
  238. data/spec/lib/license_finder/packages/license_files_spec.rb +0 -46
  239. data/spec/lib/license_finder/packages/licensing_spec.rb +0 -1
  240. data/spec/lib/license_finder/packages/possible_license_file_spec.rb +0 -38
  241. data/spec/lib/license_finder/project_finder_spec.rb +0 -33
  242. data/spec/lib/license_finder/reports/csv_report_spec.rb +0 -70
  243. data/spec/lib/license_finder/reports/diff_report_spec.rb +0 -56
  244. data/spec/lib/license_finder/reports/html_report_spec.rb +0 -101
  245. data/spec/lib/license_finder/reports/markdown_report_spec.rb +0 -45
  246. data/spec/lib/license_finder/reports/merged_report_spec.rb +0 -21
  247. data/spec/lib/license_finder/reports/text_report_spec.rb +0 -43
  248. data/spec/spec_helper.rb +0 -27
  249. data/spec/support/shared_examples_for_package_manager.rb +0 -52
  250. data/spec/support/stdout_helpers.rb +0 -31
  251. data/spec/support/test_fixtures.rb +0 -7
@@ -1,33 +0,0 @@
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
@@ -1,144 +0,0 @@
1
- require 'spec_helper'
2
- require 'fakefs/spec_helpers'
3
-
4
- module LicenseFinder
5
- describe GoVendor do
6
- include FakeFS::SpecHelpers
7
-
8
- let(:logger) { double(:logger, active: nil) }
9
- subject { GoVendor.new(options.merge(project_path: Pathname(project_path), logger: logger)) }
10
-
11
- before do
12
- allow(logger).to receive(:installed)
13
- allow(logger).to receive(:active)
14
- end
15
-
16
- context 'package manager' do
17
- before do
18
- FileUtils.mkdir_p File.join(fixture_path('all_pms'), 'vendor')
19
- end
20
-
21
- it_behaves_like "a PackageManager"
22
-
23
- it 'installed? should be true if go exists on the path' do
24
- allow(PackageManager).to receive(:command_exists?).with('go').and_return true
25
- expect(described_class.installed?).to eq(true)
26
- end
27
-
28
- it 'installed? should be false if go does not exists on the path' do
29
- allow(PackageManager).to receive(:command_exists?).with('go').and_return false
30
- expect(described_class.installed?).to eq(false)
31
- end
32
- end
33
-
34
- let(:project_path) { '/app' }
35
- let(:options) { {} }
36
-
37
- context 'when there are go files' do
38
- before do
39
- FileUtils.mkdir_p project_path
40
- FileUtils.touch File.join(project_path, 'main.go')
41
- FileUtils.mkdir_p File.join(project_path, 'vendor', 'github.com', 'foo', 'bar')
42
- FileUtils.mkdir_p File.join(project_path, 'vendor', 'golang.org', 'bar', 'baz')
43
- end
44
-
45
- it 'detects the project as go vendor project' do
46
- expect(subject.active?).to be true
47
- end
48
-
49
- describe '#current_packages' do
50
- let(:go_deps) {
51
- ["github.com/foo/bar", true]
52
- }
53
- let(:std_deps) {
54
- ["stdbar/baz", true]
55
- }
56
-
57
- before do
58
- allow(subject).to receive(:capture).with(%q[go list -f "{{join .Deps \"\n\"}}" ./...]).and_return(go_deps)
59
- allow(subject).to receive(:capture).with(%q[go list std]).and_return(std_deps)
60
- allow(subject).to receive(:capture).with(%q[git rev-list --max-count 1 HEAD]).and_return(["e0ff7ae205f\n", true])
61
- end
62
-
63
- RSpec.shared_examples 'current_packages' do |parameter|
64
- it 'only returns the parent package' do
65
- packages = subject.current_packages
66
- expect(packages.count).to eq(1)
67
- expect(packages.first.name).to eq('github.com/foo/bar')
68
- end
69
- end
70
-
71
- include_examples 'current_packages'
72
-
73
- it 'uses the sha of the parent project as the dependency version' do
74
- packages = subject.current_packages
75
- expect(packages.first.version).to eq('vendored-e0ff7ae205f')
76
- end
77
-
78
- context 'when sub packages are being used' do
79
- let(:go_deps) {
80
- ["github.com/foo/bar\ngithub.com/foo/bar/baz", true]
81
- }
82
-
83
- end
84
-
85
- context 'when only sub packages are being used' do
86
- let(:go_deps) {
87
- ["github.com/foo/bar/baz", true]
88
- }
89
-
90
- include_examples 'current_packages'
91
- end
92
-
93
- context 'when unvendored packages are being used' do
94
- let(:go_deps) {
95
- ["github.com/foo/bar\ntext/template/parse", true]
96
- }
97
-
98
- include_examples 'current_packages'
99
- end
100
-
101
- context 'when standard packages are being used' do
102
- let(:go_deps) {
103
- ["github.com/foo/bar\ngolang.org/stdbar/baz", true]
104
- }
105
-
106
- include_examples 'current_packages'
107
- end
108
-
109
- context 'when standard package names match part of a nonstandard package' do
110
- let(:go_deps) {
111
- ["github.com/foo/bar/my-stdbar/baz\ngolang.org/stdbar/baz", true]
112
- }
113
-
114
- include_examples 'current_packages'
115
-
116
- end
117
- end
118
- end
119
-
120
- context 'when there are go files in subdirectories' do
121
- before do
122
- FileUtils.mkdir_p project_path
123
- FileUtils.mkdir_p File.join(project_path, 'vendor', 'github.com', 'foo', 'bar')
124
- FileUtils.touch File.join(project_path, 'vendor', 'github.com', 'foo', 'bar', 'main.go')
125
- end
126
-
127
- it 'detects the project as go vendor project' do
128
- expect(subject.active?).to be true
129
- end
130
- end
131
-
132
- context 'if no go files exist' do
133
- let(:project_path) { '/ruby_app' }
134
-
135
- before do
136
- FileUtils.mkdir_p File.join(project_path, 'vendor')
137
- end
138
-
139
- it 'should not mark the project active' do
140
- expect(subject.active?).to be false
141
- end
142
- end
143
- end
144
- end
@@ -1,286 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module LicenseFinder
4
- describe GoWorkspace do
5
- let(:options) { {} }
6
- let(:logger) { double(:logger, active: nil) }
7
- let(:project_path) { '/Users/pivotal/workspace/loggregator'}
8
- subject { GoWorkspace.new(options.merge(project_path: Pathname(project_path), logger: logger)) }
9
-
10
- before do
11
- allow(logger).to receive(:installed)
12
- allow(logger).to receive(:active)
13
- end
14
-
15
- context 'package manager' do
16
- before do
17
- allow_any_instance_of(GoDep).to receive(:active?).and_return(false)
18
- end
19
-
20
- it_behaves_like "a PackageManager"
21
-
22
- it 'installed? should be true if go exists on the path' do
23
- allow(PackageManager).to receive(:command_exists?).with('go').and_return true
24
- expect(described_class.installed?).to eq(true)
25
- end
26
-
27
- it 'installed? should be false if go does not exists on the path' do
28
- allow(PackageManager).to receive(:command_exists?).with('go').and_return false
29
- expect(described_class.installed?).to eq(false)
30
- end
31
- end
32
-
33
- describe '#go_list' do
34
-
35
- let(:go_list_output) {
36
- <<HERE
37
- gopkg.in/yaml.v2
38
- github.com/onsi/ginkgo
39
- myblip/blop-custom
40
- encoding/json
41
- golang.org/x/tools/go/ast/astutil
42
- HERE
43
- }
44
-
45
- let(:std_packages) {
46
- <<HERE
47
- go/ast
48
- blop
49
- encoding/json
50
- HERE
51
- }
52
-
53
- before do
54
- allow(Dir).to receive(:chdir).with(Pathname.new project_path) { |&b| b.call() }
55
- allow(FileTest).to receive(:exist?).and_return(false)
56
- allow(FileTest).to receive(:exist?).with(File.join(project_path, '.envrc')).and_return(true)
57
- allow(subject).to receive(:capture).with('go list -f "{{join .Deps \"\n\"}}" ./...').and_return([go_list_output, true])
58
- allow(subject).to receive(:capture).with('go list std').and_return([std_packages, true])
59
- end
60
-
61
- it 'changes the directory' do
62
- subject.send(:go_list)
63
-
64
- expect(Dir).to have_received(:chdir)
65
- end
66
-
67
- it 'lists only non-standard packages' do
68
- packages = subject.send(:go_list)
69
- expect(packages.count).to eq(3)
70
- expect(packages).to eq(['gopkg.in/yaml.v2', 'github.com/onsi/ginkgo', 'myblip/blop-custom'])
71
- end
72
-
73
- it 'sets gopath to the envrc path' do
74
- allow(subject).to receive(:capture).with('go list -f "{{join .Deps \"\n\"}}" ./...') {
75
- expect(ENV['GOPATH']).to be_nil
76
- ['', true]
77
- }
78
-
79
- subject.send(:go_list)
80
- end
81
- end
82
-
83
- describe '#git_modules' do
84
- before do
85
- allow(FileTest).to receive(:exist?).and_return(false)
86
- allow(FileTest).to receive(:exist?).with('/Users/pivotal/workspace/loggregator/.envrc').and_return(true)
87
- allow(Dir).to receive(:chdir).with(Pathname.new '/Users/pivotal/workspace/loggregator') { |&b| b.call() }
88
- end
89
-
90
- context 'if git submodule status fails' do
91
- before do
92
- allow(subject).to receive(:capture).with('git submodule status').and_return(['', false])
93
- end
94
-
95
- it 'should raise an exception' do
96
- expect { subject.send(:git_modules) }.to raise_exception(/git submodule status failed/)
97
- end
98
- end
99
-
100
- context 'if git submodule status succeeds' do
101
- let(:git_submodule_status_output) {
102
- <<HERE
103
- 1993eafbef57be29ee8f5eb9d26a22f20ff3c207 src/github.com/GaryBoone/GoStats (heads/master)
104
- 55eb11d21d2a31a3cc93838241d04800f52e823d src/github.com/Sirupsen/logrus (v0.7.3)
105
- HERE
106
- }
107
-
108
- before do
109
- allow(subject).to receive(:capture).with('git submodule status').and_return([git_submodule_status_output, true])
110
- end
111
-
112
- it 'should return the filtered submodules' do
113
- submodules = subject.send(:git_modules)
114
- expect(submodules.count).to eq(2)
115
- expect(submodules.first.install_path).to eq('/Users/pivotal/workspace/loggregator/src/github.com/GaryBoone/GoStats')
116
- expect(submodules.first.revision).to eq('1993eafbef57be29ee8f5eb9d26a22f20ff3c207')
117
- end
118
- end
119
- end
120
-
121
- describe '#current_packages' do
122
- let(:git_modules_output) {
123
- [GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/src/bitbucket.org/kardianos/osext", "b8a35001b773c267e")]
124
- }
125
-
126
- let(:go_list_output) {
127
- [
128
- "bitbucket.org/kardianos/osext",
129
- "bitbucket.org/kardianos/osext/foo",
130
- ]
131
- }
132
-
133
-
134
- before do
135
- allow(FileTest).to receive(:exist?).and_return(true)
136
-
137
- allow(Dir).to receive(:chdir).with(Pathname('/Users/pivotal/workspace/loggregator')) { |&block| block.call }
138
- allow(subject).to receive(:go_list).and_return(go_list_output)
139
- allow(subject).to receive(:git_modules).and_return(git_modules_output)
140
- end
141
-
142
- it 'sets homepage for the packages' do
143
- packages = subject.current_packages
144
-
145
- expect(packages[0].homepage).to eq('bitbucket.org/kardianos/osext')
146
- end
147
-
148
- describe 'should return an array of go packages' do
149
- it 'provides package names' do
150
- packages = subject.current_packages
151
- expect(packages.count).to eq(1)
152
- first_package = packages.first
153
- expect(first_package.name).to eq 'bitbucket.org/kardianos/osext'
154
- expect(first_package.version).to eq 'b8a3500'
155
- expect(first_package.install_path).to eq '/Users/pivotal/workspace/loggregator/src/bitbucket.org/kardianos/osext'
156
- end
157
-
158
- it 'should filter the subpackages' do
159
- packages = subject.current_packages
160
- packages = packages.select { |p| p.name.include?("bitbucket.org") }
161
- expect(packages.count).to eq(1)
162
- end
163
-
164
- context 'when requesting the full version' do
165
- let(:options) { { go_full_version:true } }
166
- it 'list the dependencies with full version' do
167
- expect(subject.current_packages.map(&:version)).to eq ["b8a35001b773c267e"]
168
- end
169
- end
170
-
171
- context 'when the deps are in a vendor directory' do
172
- let(:git_modules_output) {
173
- [GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/vendor/src/bitbucket.org/kardianos/osext", "b8a35001b773c267e")]
174
- }
175
-
176
- it 'reports the right import path' do
177
- expect(subject.current_packages.map(&:name)).to include('bitbucket.org/kardianos/osext')
178
- end
179
-
180
- it 'reports the right install path' do
181
- expect(subject.current_packages.map(&:install_path)).to include('/Users/pivotal/workspace/loggregator/vendor/src/bitbucket.org/kardianos/osext')
182
- end
183
- end
184
-
185
- context 'when only the subpackage is being used' do
186
- let(:go_list_output) {
187
- [
188
- "bitbucket.org/kardianos/osext/foo",
189
- ]
190
- }
191
-
192
- it 'returns the top level repo name as the import path' do
193
- packages = subject.current_packages
194
- expect(packages.map(&:name)).to eq(['bitbucket.org/kardianos/osext'])
195
- end
196
- end
197
-
198
- context 'when only the subpackage is being used' do
199
- let(:git_modules_output) {
200
- [GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/vendor/src/github.com/onsi/foo", "e762c377b10053a8b"),
201
- GoWorkspace::Submodule.new("/Users/pivotal/workspace/loggregator/vendor/src/github.com/onsi/foobar", "b8a35001b773c267e")]
202
- }
203
-
204
- let(:go_list_output) {
205
- [
206
- "github.com/onsi/foo",
207
- "github.com/onsi/foobar",
208
- ]
209
- }
210
-
211
- it 'returns the top level repo name as the import path' do
212
- packages = subject.current_packages
213
- expect(packages.map(&:name)).to eq(['github.com/onsi/foo', 'github.com/onsi/foobar'])
214
- end
215
- end
216
- end
217
- end
218
-
219
- describe '#package_path' do
220
- before do
221
- allow(FileTest).to receive(:exist?).and_return(true)
222
- end
223
-
224
- it 'returns the package_path' do
225
- expect(subject.package_path).to eq Pathname('/Users/pivotal/workspace/loggregator')
226
- end
227
- end
228
-
229
- describe '#active?' do
230
- let(:envrc) { '/Users/pivotal/workspace/loggregator/.envrc' }
231
-
232
- before do
233
- allow(FileTest).to receive(:exist?).and_return(false)
234
- end
235
-
236
- it 'returns true when .envrc contains GOPATH' do
237
- allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
238
- allow(IO).to receive(:read).with(Pathname(envrc)).and_return('export GOPATH=/foo/bar')
239
- expect(subject.active?).to eq(true)
240
- end
241
-
242
- it 'returns true when .envrc contains GO15VENDOREXPERIMENT' do
243
- allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
244
- allow(IO).to receive(:read).with(Pathname(envrc)).and_return('export GO15VENDOREXPERIMENT=1')
245
- expect(subject.active?).to eq(true)
246
- end
247
-
248
- it 'returns false when .envrc does not contain GOPATH or GO15VENDOREXPERIMENT' do
249
- allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
250
- allow(IO).to receive(:read).with(Pathname(envrc)).and_return('this is not an envrc file')
251
- expect(subject.active?).to eq(false)
252
- end
253
-
254
- it 'returns false when .envrc does not exist' do
255
- expect(subject.active?).to eq(false)
256
- end
257
-
258
- it 'logs the active state' do
259
- expect(logger).to receive(:active)
260
- subject.active?
261
- end
262
-
263
- context 'when Godep is present' do
264
- let(:godeps) { '/Users/pivotal/workspace/loggregator/Godeps/Godeps.json' }
265
-
266
- it 'should prefer Godeps over go_workspace' do
267
- allow(FileTest).to receive(:exist?).with(Pathname(godeps)).and_return(true)
268
- expect(subject.active?).to eq(false)
269
- end
270
- end
271
-
272
- context 'when .envrc is present in a parent directory' do
273
- subject {
274
- GoWorkspace.new(options.merge(project_path: Pathname('/Users/pivotal/workspace/loggregator/src/github.com/foo/bar'),
275
- logger: logger))
276
- }
277
-
278
- it 'returns true' do
279
- allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
280
- allow(IO).to receive(:read).with(Pathname(envrc)).and_return('export GOPATH=/foo/bar')
281
- expect(subject.active?).to be true
282
- end
283
- end
284
- end
285
- end
286
- end