forked from ruby/rubygems
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontent_addressable_spec.rb
More file actions
337 lines (267 loc) · 12.3 KB
/
Copy pathcontent_addressable_spec.rb
File metadata and controls
337 lines (267 loc) · 12.3 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# frozen_string_literal: true
RSpec.describe "bundle install with content-addressable gems", :compact_index, rubygems: ">= 4.1.0.dev" do
before do
skip "Gem::ContentAddress not available" if ruby_core?
end
let(:current_abi) { "#{Gem.ruby_version.segments[0]}.#{Gem.ruby_version.segments[1]}" }
let(:mismatched_abi) { "#{Gem.ruby_version.segments[0] + 1}.0" }
it "installs the content-addressed gem when the Ruby ABI matches" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 content_addressed"
cached_files = Dir.glob(default_bundle_path("cache", "mygem-1.0-*.gem").to_s)
expect(cached_files.size).to eq(1), "expected exactly one cached gem file, found: #{cached_files}"
expect(cached_files.first).to match(/mygem-1\.0-[0-9a-f]{8,64}\.gem$/)
expect(default_bundle_path("cache", "mygem-1.0-x86_64-linux.gem")).not_to exist
expect(lockfile).to match(/^ mygem \(1\.0-[0-9a-f]{8,64}\) x86_64-linux$/)
end
end
it "resolves a content-addressed binary from the local cache after a lockfile round-trip" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
cached_file = Dir[default_bundle_path("cache", "mygem-1.0-*.gem").to_s].first
FileUtils.mkdir_p(bundled_app("vendor/cache"))
FileUtils.cp(cached_file, bundled_app("vendor/cache"))
gem_dir = Dir[default_bundle_path("gems", "mygem-1.0-*").to_s].first
pristine_system_gems
bundle "install --local"
expect(the_bundle).to include_gems "mygem 1.0 content_addressed"
expect(Dir[default_bundle_path("gems", "mygem-1.0-*").to_s].first).to eq(gem_dir)
end
end
it "falls back to the non-content-addressed gem when the content-addressed gem requires a different Ruby ABI" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: mismatched_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{mismatched_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 not_content_addressed"
end
end
it "does not treat a content-addressed suffix as content-addressable when platform metadata is missing" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = "abcdef12"
s.write "lib/mygem.rb", "MYGEM = '1.0 hex_platform'"
end
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }, raise_on_error: false
source "https://gem.repo2"
gem "mygem"
G
expect(err).to include("Could not find gem 'mygem'")
end
end
it "falls back to the non-content-addressed gem when the content-addressed gem is for a different platform" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("arm64-darwin")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 not_content_addressed"
end
end
it "installs the content-addressed gem matching the current platform when multiple platforms are available" do
simulate_platform "x86_64-linux" do
build_repo2
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed_linux'"
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("arm64-darwin")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed_darwin'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 content_addressed_linux"
end
end
it "falls back to the pure-ruby gem when the content-addressed gem requires a different Ruby ABI" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.write "lib/mygem.rb", "MYGEM = '1.0 pure_ruby'"
end
end
build_gem "mygem", "1.0", ruby_abi: mismatched_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{mismatched_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 pure_ruby"
end
end
it "installs the ABI-compatible content-addressed gem when multiple content-addressed gems are available for the same platform" do
simulate_platform "x86_64-linux" do
build_repo2
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed_matching_abi'"
end
build_gem "mygem", "1.0", ruby_abi: mismatched_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{mismatched_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed_mismatched_abi'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 content_addressed_matching_abi"
end
end
it "installs the higher non-content-addressed version over a lower content-addressed version" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "2.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '2.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 2.0 not_content_addressed"
end
end
it "falls back to the non-content-addressed gem when all content-addressed gems require a different Ruby ABI" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: mismatched_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{mismatched_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed_mismatched_abi_1'"
end
second_mismatched_abi = "#{Gem.ruby_version.segments[0] + 2}.0"
build_gem "mygem", "1.0", ruby_abi: second_mismatched_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{second_mismatched_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed_mismatched_abi_2'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 not_content_addressed"
end
end
it "installs a locked content-addressed gem in frozen mode" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
source "https://gem.repo2"
gem "mygem"
G
expect(the_bundle).to include_gems "mygem 1.0 content_addressed"
pristine_system_gems
bundle_config "frozen true"
bundle "install", artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
expect(the_bundle).to include_gems "mygem 1.0 content_addressed"
end
end
it "fails when the downloaded content-addressed gem hash does not match the filename" do
simulate_platform "x86_64-linux" do
build_repo2 do
build_gem "mygem", "1.0" do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
end
end
build_gem "mygem", "1.0", ruby_abi: current_abi, path: gem_repo2("gems") do |s|
s.platform = Gem::Platform.new("x86_64-linux")
s.required_ruby_version = "~> #{current_abi}.0"
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
end
ca_gem = Dir[gem_repo2("gems", "mygem-1.0-[0-9a-f]*.gem")].first
non_ca_gem = gem_repo2("gems", "mygem-1.0-x86_64-linux.gem")
FileUtils.cp non_ca_gem, ca_gem
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }, raise_on_error: false
source "https://gem.repo2"
gem "mygem"
G
expect(err).to include("content address mismatch")
end
end
end