summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-10-08 10:42:46 -0600
committermo khan <mo@mokhan.ca>2025-10-08 10:42:46 -0600
commit4072dedb8f17040f3dbe1ec8400e2eb87b044c2d (patch)
treecd7f30fc71793a914e6d9c4d3d3878b51200d064 /test
parent58d4e9be69cf5fbc951bc63858ac899dded47bee (diff)
feat: add support for streaming responses
Diffstat (limited to 'test')
-rw-r--r--test/net/client_test.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/net/client_test.rb b/test/net/client_test.rb
index 45ea419..4a688d1 100644
--- a/test/net/client_test.rb
+++ b/test/net/client_test.rb
@@ -317,4 +317,42 @@ class ClientTest < Minitest::Test
end
end
end
+
+ def test_post_with_streaming
+ chunks = ["chunk1", "chunk2", "chunk3"]
+ response_body = chunks.join
+
+ WebMock.stub_request(:post, "https://example.org/stream")
+ .to_return(status: 200, body: response_body)
+
+ uri = URI.parse('https://example.org/stream')
+ received_chunks = []
+
+ subject.post(uri, body: { test: true }) do |response|
+ response.read_body do |chunk|
+ received_chunks << chunk
+ end
+ end
+
+ assert_equal chunks.join, received_chunks.join
+ end
+
+ def test_get_with_streaming
+ chunks = ["data1\n", "data2\n", "data3\n"]
+ response_body = chunks.join
+
+ WebMock.stub_request(:get, "https://example.org/stream")
+ .to_return(status: 200, body: response_body)
+
+ uri = URI.parse('https://example.org/stream')
+ received_data = []
+
+ subject.get(uri) do |response|
+ response.read_body do |chunk|
+ received_data << chunk
+ end
+ end
+
+ assert_equal chunks.join, received_data.join
+ end
end