Skip to content

Commit

Permalink
Merge branch 'mattkasa/215391-terraform-read-request-body' into 'master'
Browse files Browse the repository at this point in the history
Test terraform state API using Unicorn::TeeInput

See merge request gitlab-org/gitlab!30334
  • Loading branch information
grzesiek committed Apr 27, 2020
2 parents 2d2ce63 + db7f9cc commit e006b8b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/requests/api/terraform/state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@

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
Expand Down Expand Up @@ -112,6 +120,14 @@

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
Expand Down
27 changes: 27 additions & 0 deletions spec/support/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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

0 comments on commit e006b8b

Please sign in to comment.