test/test_client.rb in octoparts-0.0.4 vs test/test_client.rb in octoparts-0.0.5

- old
+ new

@@ -39,18 +39,22 @@ request_meta(id: 'test', timeout: 500) requests do part_request(part_id: 'echo').add_param('fooValue', 'test') end end + stub_request(:post, 'localhost:9000') response = @client.invoke(aggregate_request) body = response.body assert { body.class == Octoparts::Model::AggregateResponse } assert { body.response_meta.class == Octoparts::Model::ResponseMeta } assert { body.responses.first.class == Octoparts::Model::PartResponse } assert { body.responses.first.cache_control.class == Octoparts::Model::CacheControl } assert { body.responses.size == 1 } assert { body.responses.first.contents =~ /"test"/ } + assert_requested(:post, "http://localhost:9000/octoparts/2") do |req| + req.body == '{"requestMeta":{"id":"test","timeout":500},"requests":[{"partId":"echo","params":[{"key":"fooValue","value":"test"}]}]}' + end end end test "normal invoke when 2 requests" do VCR.use_cassette 'invoke_with_2_requests' do @@ -98,9 +102,32 @@ "request_meta" => { "timeout" => 500 } }) end + end + end + end + + sub_test_case "timeout" do + teardown do + Octoparts.configure do |c| + c.timeout_sec = nil + end + end + + test "timeout_sec option" do + assert_raise Faraday::TimeoutError do + Octoparts::Client.new(timeout_sec: 0).get('/') + end + end + + test "open_timeout_sec option" do + Octoparts.configure do |c| + c.timeout_sec = 0 + end + assert_raise Faraday::TimeoutError do + Octoparts::Client.new.get('/') end end end end