From ca979468a42895293b738b6079af1f2d1e88d166 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 3 Oct 2024 14:40:59 +1300 Subject: [PATCH] Add test for basic post request. --- test/async/http/client/post.rb | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/async/http/client/post.rb diff --git a/test/async/http/client/post.rb b/test/async/http/client/post.rb new file mode 100644 index 0000000..586aab0 --- /dev/null +++ b/test/async/http/client/post.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2018-2024, by Samuel Williams. + +require "sus/fixtures/async/http" + +APostRequest = Sus::Shared("a post request") do + include Sus::Fixtures::Async::HTTP::ServerContext + + let(:app) do + ::Protocol::HTTP::Middleware.for do |request| + ::Protocol::HTTP::Response[200, {}, request.body] + end + end + + it "can post a fixed length body" do + body = Protocol::HTTP::Body::Buffered.wrap(["Hello, World!"]) + + begin + response = client.post("/", body: body) + + expect(response).to be(:success?) + expect(response.read).to be == "Hello, World!" + ensure + response&.finish + end + end +end + +describe Async::HTTP::Protocol::HTTP10 do + it_behaves_like APostRequest +end + +describe Async::HTTP::Protocol::HTTP11 do + it_behaves_like APostRequest +end + +describe Async::HTTP::Protocol::HTTP2 do + it_behaves_like APostRequest +end