-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathgradle_test.rb
192 lines (162 loc) · 6.35 KB
/
gradle_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# frozen_string_literal: true
require "test_helper"
require "tmpdir"
require "fileutils"
if Licensed::Shell.tool_available?("gradle")
describe Licensed::Sources::Gradle do
let(:opts) { { "source_path" => fixtures, "root" => root } }
let(:config) { Licensed::AppConfiguration.new(opts) }
let(:source) { Licensed::Sources::Gradle.new(config) }
describe "Single project" do
let(:root) { File.expand_path("../../fixtures/gradle/single_project", __FILE__) }
let(:fixtures) { root }
describe "enabled?" do
it "is true if build.gradle exists and gradle is available" do
Dir.chdir(fixtures) do
assert source.enabled?
end
end
it "is false if build.gradle does not exist" do
Dir.chdir(Dir.tmpdir) do
refute source.enabled?
end
end
end
describe "dependencies" do
it "includes declared dependencies" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "io.netty:netty-all" }
assert dep
assert_equal "gradle", dep.record["type"]
assert_equal "4.1.33.Final", dep.version
end
end
it "does not include test dependencies" do
Dir.chdir fixtures do
refute source.dependencies.detect { |d| d.name == "org.junit.jupiter:junit-jupiter" }
end
end
it "cleans up grade licenses csv content" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "io.netty:netty-all" }
# load the dependency record which creates temp license-*.gradle files
dep.record
refute Dir.glob(Pathname.pwd.join("license-*.gradle").to_path).any?
end
end
end
end
describe "Multi project" do
let(:root) { File.expand_path("../../fixtures/gradle/multi_project", __FILE__) }
describe "app subproject" do
let(:fixtures) { File.join(root, "app") }
describe "enabled?" do
it "is true if build.gradle exists and gradle is available" do
Dir.chdir(fixtures) do
assert source.enabled?
end
end
it "is false if build.gradle does not exist" do
Dir.chdir(Dir.tmpdir) do
refute source.enabled?
end
end
end
describe "dependencies" do
it "includes declared dependencies" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "com.google.guava:guava" }
assert dep
assert_equal "gradle", dep.record["type"]
assert_equal "31.1-jre", dep.version
end
end
it "does not include test dependencies" do
Dir.chdir fixtures do
refute source.dependencies.detect { |d| d.name == "org.junit.jupiter:junit-jupiter-engine" }
end
end
it "cleans up grade licenses csv content" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "com.google.guava:guava" }
# load the dependency record which creates temp license-*.gradle files
dep.record
refute Dir.glob(Pathname.pwd.join("license-*.gradle").to_path).any?
end
end
end
end
describe "lib subproject" do
let(:fixtures) { File.join(root, "lib") }
describe "enabled?" do
it "is true if build.gradle exists and gradle is available" do
Dir.chdir(fixtures) do
assert source.enabled?
end
end
it "is false if build.gradle does not exist" do
Dir.chdir(Dir.tmpdir) do
refute source.enabled?
end
end
end
describe "dependencies" do
it "includes declared dependencies" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "com.google.guava:guava" }
assert dep
assert_equal "gradle", dep.record["type"]
assert_equal "31.1-jre", dep.version
end
end
it "does not include test dependencies" do
Dir.chdir fixtures do
refute source.dependencies.detect { |d| d.name == "org.junit.jupiter:junit-jupiter-engine" }
end
end
it "cleans up grade licenses csv content" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "com.google.guava:guava" }
# load the dependency record which creates temp license-*.gradle files
dep.record
refute Dir.glob(Pathname.pwd.join("license-*.gradle").to_path).any?
end
end
end
end
end
end
describe Licensed::Sources::Gradle::Dependency do
let(:fixtures) { File.expand_path("../../fixtures/gradle/single_project", __FILE__) }
let(:config) { Licensed::AppConfiguration.new({ "source_path" => fixtures, "root" => fixtures }) }
let(:source) { Licensed::Sources::Gradle.new(config) }
it "returns the dependency license" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "io.netty:netty-all" }
assert dep
assert_equal "apache-2.0", dep.license.key
license = dep.record.licenses.find { |l| l.text =~ /Apache License/ }
assert license
assert_equal ["https://www.apache.org/licenses/LICENSE-2.0"], license.sources
end
end
it "cleans up grade licenses csv content" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "io.netty:netty-all" }
# load the dependency record, pulling license files
dep.record
refute Pathname.pwd.join(Licensed::Sources::Gradle::GRADLE_LICENSES_PATH).exist?
end
end
it "does not make any network requests when accessing non-license data" do
Licensed::Sources::Gradle::Dependency.expects(:retrieve_license).never
Licensed::Sources::Gradle::Dependency.expects(:load_csv).never
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "io.netty:netty-all" }
# accessing non-license dependency data does not make network requests
dep.name
dep.version
end
end
end
end