Skip to content

Commit

Permalink
Added a test case for 304s
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnowzari committed Feb 28, 2025
1 parent 194416c commit 8e5daf8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/lib/crawler/http_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,46 @@
end
end

context 'when HEAD returns a redirect with no location' do
let(:head_response) do
double(
:apache_response,
status_code: 304,
close: true,
headers: [],
entity: nil
)
end
let(:get_response) do
double(
:apache_response,
status_code: 304,
close: true,
headers: [content_type_header],
entity: response_entity
)
end

before do
allow(head_response).to receive(:getCode).and_return(304)
allow(get_response).to receive(:getCode).and_return(304)
allow(logger).to receive(:warn)
allow(Crawler::Data::CrawlResult::RedirectError).to receive(:new)
end

it 'receives a RedirectError and log message' do
http_executor.run(crawl_task)

# expect one log message
expect(logger).to have_received(:warn).with(
match(/^Redirect from #{crawl_task.url} dropped due to lack of redirect location. .*/)
).once

# expect one RedirectError
expect(Crawler::Data::CrawlResult::RedirectError).to have_received(:new).once
end
end

context 'when HEAD returns a redirect' do
let(:redirect_url) { 'https://example.com/info' }
let(:crawler_redirect_url) { Crawler::Data::URL.parse(redirect_url) }
Expand Down

0 comments on commit 8e5daf8

Please sign in to comment.