Commit e006b8b0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'mattkasa/215391-terraform-read-request-body' into 'master'

Test terraform state API using Unicorn::TeeInput

See merge request gitlab-org/gitlab!30334
parents 2d2ce63d db7f9cc2
......@@ -78,6 +78,14 @@ describe API::Terraform::State do
expect(response).to have_gitlab_http_status(:ok)
end
context 'on Unicorn', :unicorn do
it 'updates the state' do
expect { request }.to change { Terraform::State.count }.by(0)
expect(response).to have_gitlab_http_status(:ok)
end
end
end
context 'without body' do
......@@ -112,6 +120,14 @@ describe API::Terraform::State do
expect(response).to have_gitlab_http_status(:ok)
end
context 'on Unicorn', :unicorn do
it 'creates a new state' do
expect { request }.to change { Terraform::State.count }.by(1)
expect(response).to have_gitlab_http_status(:ok)
end
end
end
context 'without body' do
......
# frozen_string_literal: true
REQUEST_CLASSES = [
::Grape::Request,
::Rack::Request
].freeze
def request_body_class
return ::Unicorn::TeeInput if defined?(::Unicorn)
Class.new(StringIO) do
def string
raise NotImplementedError, '#string is only valid under Puma which uses StringIO, use #read instead'
end
end
end
RSpec.configure do |config|
config.before(:each, :unicorn) do
REQUEST_CLASSES.each do |request_class|
allow_any_instance_of(request_class)
.to receive(:body).and_wrap_original do |m, *args|
request_body_class.new(m.call(*args).read)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment