|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe "fetching dependencies with a not available mirror" do |
4 | | - let(:host) { "127.0.0.1" } |
5 | | - |
6 | 4 | before do |
7 | | - require_rack_test |
8 | | - setup_server |
9 | | - setup_mirror |
10 | | - end |
| 5 | + build_repo2 |
11 | 6 |
|
12 | | - after do |
13 | | - Artifice.deactivate |
14 | | - @server_thread.kill |
15 | | - @server_thread.join |
| 7 | + gemfile <<-G |
| 8 | + source "https://gem.repo2" |
| 9 | + gem 'weakling' |
| 10 | + G |
16 | 11 | end |
17 | 12 |
|
18 | 13 | context "with a specific fallback timeout" do |
19 | 14 | before do |
20 | | - global_config("BUNDLE_MIRROR__HTTP://127__0__0__1:#{@server_port}/__FALLBACK_TIMEOUT/" => "true", |
21 | | - "BUNDLE_MIRROR__HTTP://127__0__0__1:#{@server_port}/" => @mirror_uri) |
| 15 | + global_config("BUNDLE_MIRROR__HTTPS://GEM__REPO2/__FALLBACK_TIMEOUT/" => "true", |
| 16 | + "BUNDLE_MIRROR__HTTPS://GEM__REPO2/" => "https://gem.mirror") |
22 | 17 | end |
23 | 18 |
|
24 | 19 | it "install a gem using the original uri when the mirror is not responding" do |
25 | | - gemfile <<-G |
26 | | - source "#{@server_uri}" |
27 | | - gem 'weakling' |
28 | | - G |
29 | | - |
30 | | - bundle :install, artifice: nil |
| 20 | + bundle :install, env: { "BUNDLER_SPEC_FAKE_RESOLVE" => "gem.mirror" }, verbose: true |
31 | 21 |
|
32 | 22 | expect(out).to include("Installing weakling") |
33 | 23 | expect(out).to include("Bundle complete") |
|
38 | 28 | context "with a global fallback timeout" do |
39 | 29 | before do |
40 | 30 | global_config("BUNDLE_MIRROR__ALL__FALLBACK_TIMEOUT/" => "1", |
41 | | - "BUNDLE_MIRROR__ALL" => @mirror_uri) |
| 31 | + "BUNDLE_MIRROR__ALL" => "https://gem.mirror") |
42 | 32 | end |
43 | 33 |
|
44 | 34 | it "install a gem using the original uri when the mirror is not responding" do |
45 | | - gemfile <<-G |
46 | | - source "#{@server_uri}" |
47 | | - gem 'weakling' |
48 | | - G |
49 | | - |
50 | | - bundle :install, artifice: nil |
| 35 | + bundle :install, env: { "BUNDLER_SPEC_FAKE_RESOLVE" => "gem.mirror" } |
51 | 36 |
|
52 | 37 | expect(out).to include("Installing weakling") |
53 | 38 | expect(out).to include("Bundle complete") |
|
57 | 42 |
|
58 | 43 | context "with a specific mirror without a fallback timeout" do |
59 | 44 | before do |
60 | | - global_config("BUNDLE_MIRROR__HTTP://127__0__0__1:#{@server_port}/" => @mirror_uri) |
| 45 | + global_config("BUNDLE_MIRROR__HTTPS://GEM__REPO2/" => "https://gem.mirror") |
61 | 46 | end |
62 | 47 |
|
63 | 48 | it "fails to install the gem with a timeout error when the mirror is not responding" do |
64 | | - gemfile <<-G |
65 | | - source "#{@server_uri}" |
66 | | - gem 'weakling' |
67 | | - G |
| 49 | + bundle :install, artifice: "compact_index_mirror_down", raise_on_error: false |
68 | 50 |
|
69 | | - bundle :install, artifice: nil, raise_on_error: false |
70 | | - |
71 | | - expect(out).to include("Fetching source index from #{@mirror_uri}") |
72 | | - |
73 | | - err_lines = err.split("\n") |
74 | | - expect(err_lines).to include(%r{\ARetrying fetcher due to error \(2/4\): Bundler::HTTPError Could not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
75 | | - expect(err_lines).to include(%r{\ARetrying fetcher due to error \(3/4\): Bundler::HTTPError Could not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
76 | | - expect(err_lines).to include(%r{\ARetrying fetcher due to error \(4/4\): Bundler::HTTPError Could not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
77 | | - expect(err_lines).to include(%r{\ACould not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
| 51 | + expect(out).to be_empty |
| 52 | + expect(err).to eq("Could not reach host gem.mirror. Check your network connection and try again.") |
78 | 53 | end |
79 | 54 | end |
80 | 55 |
|
81 | 56 | context "with a global mirror without a fallback timeout" do |
82 | 57 | before do |
83 | | - global_config("BUNDLE_MIRROR__ALL" => @mirror_uri) |
| 58 | + global_config("BUNDLE_MIRROR__ALL" => "https://gem.mirror") |
84 | 59 | end |
85 | 60 |
|
86 | 61 | it "fails to install the gem with a timeout error when the mirror is not responding" do |
87 | | - gemfile <<-G |
88 | | - source "#{@server_uri}" |
89 | | - gem 'weakling' |
90 | | - G |
91 | | - |
92 | | - bundle :install, artifice: nil, raise_on_error: false |
93 | | - |
94 | | - expect(out).to include("Fetching source index from #{@mirror_uri}") |
| 62 | + bundle :install, artifice: "compact_index_mirror_down", raise_on_error: false |
95 | 63 |
|
96 | | - err_lines = err.split("\n") |
97 | | - expect(err_lines).to include(%r{\ARetrying fetcher due to error \(2/4\): Bundler::HTTPError Could not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
98 | | - expect(err_lines).to include(%r{\ARetrying fetcher due to error \(3/4\): Bundler::HTTPError Could not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
99 | | - expect(err_lines).to include(%r{\ARetrying fetcher due to error \(4/4\): Bundler::HTTPError Could not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
100 | | - expect(err_lines).to include(%r{\ACould not fetch specs from #{@mirror_uri}/ due to underlying error <}) |
| 64 | + expect(out).to be_empty |
| 65 | + expect(err).to eq("Could not reach host gem.mirror. Check your network connection and try again.") |
101 | 66 | end |
102 | 67 | end |
103 | | - |
104 | | - def setup_server |
105 | | - @server_port = find_unused_port |
106 | | - @server_uri = "http://#{host}:#{@server_port}" |
107 | | - |
108 | | - require_relative "../../support/artifice/compact_index" |
109 | | - require_relative "../../support/silent_logger" |
110 | | - |
111 | | - require "rackup/server" |
112 | | - |
113 | | - @server_thread = Thread.new do |
114 | | - Rackup::Server.start(app: CompactIndexAPI, |
115 | | - Host: host, |
116 | | - Port: @server_port, |
117 | | - server: "webrick", |
118 | | - AccessLog: [], |
119 | | - Logger: Spec::SilentLogger.new) |
120 | | - end.run |
121 | | - |
122 | | - wait_for_server(host, @server_port) |
123 | | - end |
124 | | - |
125 | | - def setup_mirror |
126 | | - @mirror_port = find_unused_port |
127 | | - @mirror_uri = "http://#{host}:#{@mirror_port}" |
128 | | - end |
129 | 68 | end |
0 commit comments