mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-09-22 00:00:29 -04:00
added tests for all supported mime type detectors
This commit is contained in:
parent
f05dad7785
commit
317ed07dba
10
Gemfile
10
Gemfile
@ -5,7 +5,11 @@ ruby RUBY_VERSION
|
||||
source "https://rubygems.org"
|
||||
gemspec
|
||||
|
||||
gem "rake", "~> 12.3"
|
||||
if RUBY_VERSION < "2.2.0"
|
||||
gem "rake", "~> 12.3"
|
||||
else
|
||||
gem "rake", "~> 13.0"
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem "ddtrace"
|
||||
@ -13,6 +17,7 @@ group :test do
|
||||
gem "minitest"
|
||||
gem "minitest-proveit"
|
||||
gem "ruby-ntlm"
|
||||
gem "spy"
|
||||
gem "webmock"
|
||||
gem "websocket-driver"
|
||||
|
||||
@ -23,6 +28,9 @@ group :test do
|
||||
gem "google-protobuf", "< 3.19.2" if RUBY_VERSION < "2.5.0"
|
||||
gem "grpc"
|
||||
gem "logging"
|
||||
gem "marcel", require: false
|
||||
gem "mimemagic", require: false
|
||||
gem "ruby-filemagic", require: false
|
||||
end
|
||||
end
|
||||
|
||||
|
26
standalone_tests/multipart_filemagic_test.rb
Normal file
26
standalone_tests/multipart_filemagic_test.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "filemagic"
|
||||
require "test_helper"
|
||||
require "spy"
|
||||
require "support/http_helpers"
|
||||
require "support/minitest_extensions"
|
||||
|
||||
class MultipartFilemagicTest < Minitest::Test
|
||||
include HTTPHelpers
|
||||
|
||||
def test_plugin_multipart_filemagic_file_upload
|
||||
assert defined?(FileMagic)
|
||||
|
||||
filemagic_spy = Spy.on(FileMagic, :open).and_call_through
|
||||
|
||||
response = HTTPX.plugin(:multipart)
|
||||
.post("https://#{httpbin}/post", form: { image: File.new(fixture_file_path) })
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Content-Type", "multipart/form-data")
|
||||
verify_uploaded_image(body, "image", "image/jpeg")
|
||||
|
||||
assert filemagic_spy.has_been_called?
|
||||
end unless RUBY_ENGINE == "jruby"
|
||||
end
|
26
standalone_tests/multipart_marcel_test.rb
Normal file
26
standalone_tests/multipart_marcel_test.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "marcel"
|
||||
require "test_helper"
|
||||
require "spy"
|
||||
require "support/http_helpers"
|
||||
require "support/minitest_extensions"
|
||||
|
||||
class MultipartMarcelTest < Minitest::Test
|
||||
include HTTPHelpers
|
||||
|
||||
def test_plugin_multipart_marcel_file_upload
|
||||
assert defined?(Marcel)
|
||||
|
||||
marcel_spy = Spy.on(Marcel::MimeType, :for).and_call_through
|
||||
|
||||
response = HTTPX.plugin(:multipart)
|
||||
.post("https://#{httpbin}/post", form: { image: File.new(fixture_file_path) })
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Content-Type", "multipart/form-data")
|
||||
verify_uploaded_image(body, "image", "image/jpeg")
|
||||
|
||||
assert marcel_spy.has_been_called?
|
||||
end
|
||||
end
|
26
standalone_tests/multipart_mimemagic_test.rb
Normal file
26
standalone_tests/multipart_mimemagic_test.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "mimemagic"
|
||||
require "test_helper"
|
||||
require "spy"
|
||||
require "support/http_helpers"
|
||||
require "support/minitest_extensions"
|
||||
|
||||
class MultipartMimemagicTest < Minitest::Test
|
||||
include HTTPHelpers
|
||||
|
||||
def test_plugin_multipart_mimemagic_file_upload
|
||||
assert defined?(MimeMagic)
|
||||
|
||||
mimemagic_spy = Spy.on(MimeMagic, :by_magic).and_call_through
|
||||
|
||||
response = HTTPX.plugin(:multipart)
|
||||
.post("https://#{httpbin}/post", form: { image: File.new(fixture_file_path) })
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Content-Type", "multipart/form-data")
|
||||
verify_uploaded_image(body, "image", "image/jpeg")
|
||||
|
||||
assert mimemagic_spy.has_been_called?
|
||||
end
|
||||
end
|
@ -18,20 +18,20 @@ deb-src http://deb.debian.org/debian sid main contrib non-free" >> /etc/apt/sour
|
||||
apt-get update && apt-get install -y build-essential iptables iproute2 openssl libssl-dev ca-certificates file idn2
|
||||
update-ca-certificates
|
||||
elif [[ ${RUBY_VERSION:0:3} = "2.1" ]]; then
|
||||
apt-get update && apt-get install -y libsodium-dev iptables iproute2
|
||||
apt-get update && apt-get install -y libsodium-dev iptables iproute2 libmagic-dev shared-mime-info
|
||||
IPTABLES=iptables
|
||||
elif [[ ${RUBY_VERSION:0:3} = "2.2" ]]; then
|
||||
apt-get update && apt-get install -y iptables iproute2
|
||||
apt-get update && apt-get install -y iptables iproute2 libmagic-dev shared-mime-info
|
||||
IPTABLES=iptables
|
||||
elif [[ ${RUBY_VERSION:0:3} = "2.3" ]]; then
|
||||
# installing custom openssl
|
||||
apt-get update && apt-get install -y iptables iproute2 iptables-nftables-compat # openssl=1.0.2l openssl-dev=1.0.2l
|
||||
apt-get update && apt-get install -y iptables iproute2 iptables-nftables-compat libmagic-dev shared-mime-info # openssl=1.0.2l openssl-dev=1.0.2l
|
||||
wget http://deb.debian.org/debian/pool/main/o/openssl1.0/libssl1.0.2_1.0.2u-1~deb9u1_amd64.deb
|
||||
dpkg -i libssl1.0.2_1.0.2u-1~deb9u1_amd64.deb
|
||||
wget http://deb.debian.org/debian/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2u-1~deb9u1_amd64.deb
|
||||
dpkg -i libssl1.0-dev_1.0.2u-1~deb9u1_amd64.deb
|
||||
else
|
||||
apt-get update && apt-get install -y iptables iproute2 idn2
|
||||
apt-get update && apt-get install -y iptables iproute2 idn2 libmagic-dev shared-mime-info
|
||||
fi
|
||||
|
||||
# use port 9090 to test connection timeouts
|
||||
@ -57,6 +57,7 @@ if [[ "$RUBY_ENGINE" = "truffleruby" ]]; then
|
||||
gem install bundler -v="2.1.4" --no-doc --conservative
|
||||
fi
|
||||
|
||||
export BUNDLE_WITHOUT=website
|
||||
bundle install --quiet
|
||||
|
||||
echo "Waiting for S3 at address ${AMZ_HOST}/health, attempting every 5s"
|
||||
@ -81,7 +82,7 @@ PARALLEL=1 bundle exec rake test
|
||||
# standalone tests
|
||||
for f in standalone_tests/*_test.rb
|
||||
do
|
||||
COVERAGE_KEY="$RUBY_ENGINE-$RUBY_VERSION-$(basename $f .rb)" bundle exec ruby -Itest $f
|
||||
COVERAGE_KEY="$RUBY_ENGINE-$RUBY_VERSION-$(basename $f .rb)" bundle exec ruby -Itest $f > /dev/nulll
|
||||
done
|
||||
|
||||
# third party modules
|
||||
|
Loading…
x
Reference in New Issue
Block a user