|
76 | 76 | }).to_return(body: lambda { |req| if retry_p; response_json.to_json; else; retry_p = true; raise Timeout::Error.new("execution expired"); end })
|
77 | 77 |
|
78 | 78 | sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
|
79 |
| - sc.has_next?.should be_true |
80 |
| - sc.advance.should be_true |
81 |
| - retry_p.should be_true |
| 79 | + expect(sc.has_next?).to eq true |
| 80 | + expect(sc.advance).to eq true |
| 81 | + expect(retry_p).to eq true |
82 | 82 | end
|
83 | 83 |
|
84 | 84 | it "uses 'Accept: application/x-msgpack' if option is set" do
|
|
108 | 108 |
|
109 | 109 | options.merge!(http_open_timeout: 1, enable_x_msgpack: "application/x-msgpack")
|
110 | 110 | sc = StatementClient.new(faraday, query, options)
|
111 |
| - sc.has_next?.should be_true |
112 |
| - sc.advance.should be_true |
113 |
| - retry_p.should be_true |
| 111 | + expect(sc.has_next?).to eq true |
| 112 | + expect(sc.advance).to eq true |
| 113 | + expect(retry_p).to eq true |
114 | 114 | end
|
115 | 115 |
|
116 | 116 | # trino version could be "V0_ddd" or "Vddd"
|
|
127 | 127 | "connectorHandle" => {}
|
128 | 128 | }
|
129 | 129 | })
|
130 |
| - dh.handle.should be_a_kind_of Models::TableHandle |
131 |
| - dh.handle.connector_id.should == "c1" |
132 |
| - dh.handle.connector_handle.should == {} |
| 130 | + expect(dh.handle).to be_a_kind_of Models::TableHandle |
| 131 | + expect(dh.handle.connector_id).to eq "c1" |
| 132 | + expect(dh.handle.connector_handle).to eq {} |
133 | 133 | end
|
134 | 134 |
|
135 | 135 | it "validates models" do
|
136 |
| - lambda do |
| 136 | + expect do |
137 | 137 | Models::DeleteHandle.decode({
|
138 | 138 | "handle" => "invalid"
|
139 | 139 | })
|
140 |
| - end.should raise_error(TypeError, /String to Hash/) |
| 140 | + end.to raise_error(TypeError, /String to Hash/) |
141 | 141 | end
|
142 | 142 | else
|
143 | 143 | it "decodes DeleteTarget" do
|
|
147 | 147 | "connectorHandle" => {}
|
148 | 148 | }
|
149 | 149 | })
|
150 |
| - dh.handle.should be_a_kind_of Models::TableHandle |
151 |
| - dh.handle.catalog_name.should == "c1" |
152 |
| - dh.handle.connector_handle.should == {} |
| 150 | + expect(dh.handle).to be_a_kind_of(Models::TableHandle) |
| 151 | + expect(dh.handle.catalog_name).to eq "c1" |
| 152 | + expect(dh.handle.connector_handle).to eq({}) |
153 | 153 | end
|
154 | 154 |
|
155 | 155 | it "validates models" do
|
156 |
| - lambda do |
| 156 | + expect do |
157 | 157 | Models::DeleteTarget.decode({
|
158 | 158 | "catalogName" => "c1",
|
159 | 159 | "handle" => "invalid"
|
160 | 160 | })
|
161 |
| - end.should raise_error(TypeError, /String to Hash/) |
| 161 | + end.to raise_error(TypeError, /String to Hash/) |
162 | 162 | end
|
163 | 163 | end
|
164 | 164 |
|
|
167 | 167 | with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"})
|
168 | 168 |
|
169 | 169 | sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
|
170 |
| - sc.current_results_headers["X-Test-Header"].should == "123" |
| 170 | + expect(sc.current_results_headers["X-Test-Header"]).to eq "123" |
171 | 171 | end
|
172 | 172 |
|
173 | 173 | it "receives headers of POST through Query" do
|
174 | 174 | stub_request(:post, "localhost/v1/statement").
|
175 | 175 | with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"})
|
176 | 176 |
|
177 | 177 | q = Trino::Client.new(options).query(query)
|
178 |
| - q.current_results_headers["X-Test-Header"].should == "123" |
| 178 | + expect(q.current_results_headers["X-Test-Header"]).to eq "123" |
179 | 179 | end
|
180 | 180 |
|
181 | 181 | describe "#query_id" do
|
|
187 | 187 | to_return(body: response_json.to_json, headers: {"X-Test-Header" => "123"})
|
188 | 188 |
|
189 | 189 | sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
|
190 |
| - sc.query_id.should == "queryid" |
191 |
| - sc.has_next?.should be_true |
192 |
| - sc.advance.should be_true |
193 |
| - sc.query_id.should == "queryid" |
| 190 | + expect(sc.query_id).to eq "queryid" |
| 191 | + expect(sc.has_next?).to eq true |
| 192 | + expect(sc.advance).to eq true |
| 193 | + expect(sc.query_id).to eq "queryid" |
194 | 194 | end
|
195 | 195 | end
|
196 | 196 |
|
|
214 | 214 | end
|
215 | 215 |
|
216 | 216 | it "raises an exception with sample JSON if response is unexpected" do
|
217 |
| - lambda do |
| 217 | + expect do |
218 | 218 | stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
|
219 | 219 | with(headers: headers).
|
220 | 220 | to_return(body: {"session" => "invalid session structure"}.to_json)
|
221 | 221 | statement_client.query_info
|
222 |
| - end.should raise_error(TrinoHttpError, /Trino API returned unexpected structure at \/v1\/query\/queryid\. Expected Trino::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/) |
| 222 | + end.to raise_error(TrinoHttpError, /Trino API returned unexpected structure at \/v1\/query\/queryid\. Expected Trino::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/) |
223 | 223 | end
|
224 | 224 |
|
225 | 225 | it "raises an exception if response format is unexpected" do
|
226 |
| - lambda do |
| 226 | + expect do |
227 | 227 | stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
|
228 | 228 | with(headers: headers).
|
229 | 229 | to_return(body: "unexpected data structure (not JSON)")
|
230 | 230 | statement_client.query_info
|
231 |
| - end.should raise_error(TrinoHttpError, /Trino API returned unexpected data format./) |
| 231 | + end.to raise_error(TrinoHttpError, /Trino API returned unexpected data format./) |
232 | 232 | end
|
233 | 233 |
|
234 | 234 | it "is redirected if server returned 301" do
|
|
241 | 241 | to_return(body: {"queryId" => "queryid"}.to_json)
|
242 | 242 |
|
243 | 243 | query_info = statement_client.query_info
|
244 |
| - query_info.query_id.should == "queryid" |
| 244 | + expect(query_info.query_id).to eq "queryid" |
245 | 245 | end
|
246 | 246 | end
|
247 | 247 |
|
|
345 | 345 | end
|
346 | 346 |
|
347 | 347 | it "forbids using basic auth when ssl is disabled" do
|
348 |
| - lambda do |
| 348 | + expect do |
349 | 349 | Query.__send__(:faraday_client, {
|
350 | 350 | server: 'localhost',
|
351 | 351 | password: 'abcd'
|
352 | 352 | })
|
353 |
| - end.should raise_error(ArgumentError) |
| 353 | + end.to raise_error(ArgumentError) |
354 | 354 | end
|
355 | 355 | end
|
356 | 356 |
|
|
359 | 359 | f = Query.__send__(:faraday_client, {
|
360 | 360 | server: "localhost",
|
361 | 361 | })
|
362 |
| - f.url_prefix.to_s.should == "http://localhost/" |
| 362 | + expect(f.url_prefix.to_s).to eq "http://localhost/" |
363 | 363 | end
|
364 | 364 |
|
365 | 365 | it "is enabled with ssl: true" do
|
366 | 366 | f = Query.__send__(:faraday_client, {
|
367 | 367 | server: "localhost",
|
368 | 368 | ssl: true,
|
369 | 369 | })
|
370 |
| - f.url_prefix.to_s.should == "https://localhost/" |
371 |
| - f.ssl.verify?.should == true |
| 370 | + expect(f.url_prefix.to_s).to eq "https://localhost/" |
| 371 | + expect(f.ssl.verify?).to eq true |
372 | 372 | end
|
373 | 373 |
|
374 | 374 | it "is enabled with ssl: {verify: false}" do
|
375 | 375 | f = Query.__send__(:faraday_client, {
|
376 | 376 | server: "localhost",
|
377 | 377 | ssl: {verify: false}
|
378 | 378 | })
|
379 |
| - f.url_prefix.to_s.should == "https://localhost/" |
380 |
| - f.ssl.verify?.should == false |
| 379 | + expect(f.url_prefix.to_s).to eq "https://localhost/" |
| 380 | + expect(f.ssl.verify?).to eq false |
381 | 381 | end
|
382 | 382 |
|
383 | 383 | it "rejects invalid ssl: verify: object" do
|
384 |
| - lambda do |
| 384 | + expect do |
385 | 385 | f = Query.__send__(:faraday_client, {
|
386 | 386 | server: "localhost",
|
387 | 387 | ssl: {verify: "??"}
|
388 | 388 | })
|
389 |
| - end.should raise_error(ArgumentError, /String/) |
| 389 | + end.to raise_error(ArgumentError, /String/) |
390 | 390 | end
|
391 | 391 |
|
392 | 392 | it "is enabled with ssl: Hash" do
|
|
405 | 405 | ssl: ssl,
|
406 | 406 | })
|
407 | 407 |
|
408 |
| - f.url_prefix.to_s.should == "https://localhost/" |
409 |
| - f.ssl.verify?.should == true |
410 |
| - f.ssl.ca_file.should == ssl[:ca_file] |
411 |
| - f.ssl.ca_path.should == ssl[:ca_path] |
412 |
| - f.ssl.cert_store.should == ssl[:cert_store] |
413 |
| - f.ssl.client_cert.should == ssl[:client_cert] |
414 |
| - f.ssl.client_key.should == ssl[:client_key] |
| 408 | + expect(f.url_prefix.to_s).to eq "https://localhost/" |
| 409 | + expect(f.ssl.verify?).to eq true |
| 410 | + expect(f.ssl.ca_file).to eq ssl[:ca_file] |
| 411 | + expect(f.ssl.ca_path).to eq ssl[:ca_path] |
| 412 | + expect(f.ssl.cert_store).to eq ssl[:cert_store] |
| 413 | + expect(f.ssl.client_cert).to eq ssl[:client_cert] |
| 414 | + expect(f.ssl.client_key).to eq ssl[:client_key] |
415 | 415 | end
|
416 | 416 |
|
417 | 417 | it "rejects an invalid string" do
|
418 |
| - lambda do |
| 418 | + expect do |
419 | 419 | Query.__send__(:faraday_client, {
|
420 | 420 | server: "localhost",
|
421 | 421 | ssl: '??',
|
422 | 422 | })
|
423 |
| - end.should raise_error(ArgumentError, /String/) |
| 423 | + end.to raise_error(ArgumentError, /String/) |
424 | 424 | end
|
425 | 425 |
|
426 | 426 | it "rejects an integer" do
|
427 |
| - lambda do |
| 427 | + expect do |
428 | 428 | Query.__send__(:faraday_client, {
|
429 | 429 | server: "localhost",
|
430 | 430 | ssl: 3,
|
431 | 431 | })
|
432 |
| - end.should raise_error(ArgumentError, /:ssl/) |
| 432 | + end.to raise_error(ArgumentError, /:ssl/) |
433 | 433 | end
|
434 | 434 | end
|
435 | 435 |
|
|
440 | 440 |
|
441 | 441 | faraday = Faraday.new(url: "http://localhost")
|
442 | 442 | client = StatementClient.new(faraday, query, options.merge(model_version: "316"))
|
443 |
| - client.current_results.should be_a_kind_of(ModelVersions::V316::QueryResults) |
| 443 | + expect(client.current_results).to be_a_kind_of(ModelVersions::V316::QueryResults) |
444 | 444 | end
|
445 | 445 |
|
446 | 446 | it "rejects unsupported model version" do
|
447 |
| - lambda do |
| 447 | + expect do |
448 | 448 | StatementClient.new(faraday, query, options.merge(model_version: "0.111"))
|
449 |
| - end.should raise_error(NameError) |
| 449 | + end.to raise_error(NameError) |
450 | 450 | end
|
451 | 451 |
|
452 | 452 | let :nested_json do
|
|
543 | 543 | stub_request(:get, "localhost/v1/next_uri").
|
544 | 544 | with(headers: headers).
|
545 | 545 | to_return(body: planning_response.to_json)
|
546 |
| - lambda do |
| 546 | + expect do |
547 | 547 | client.advance
|
548 |
| - end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") |
| 548 | + end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") |
549 | 549 | end
|
550 | 550 |
|
551 | 551 | it "raises TrinoQueryTimeoutError if timeout during initial resuming" do
|
552 | 552 | stub_request(:get, "localhost/v1/next_uri").
|
553 | 553 | with(headers: headers).
|
554 | 554 | to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") })
|
555 | 555 |
|
556 |
| - lambda do |
| 556 | + expect do |
557 | 557 | StatementClient.new(faraday, query, options.merge(timeout_type => 1), "/v1/next_uri")
|
558 |
| - end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query timed out") |
| 558 | + end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query timed out") |
559 | 559 | end
|
560 | 560 |
|
561 | 561 | it "raises TrinoHttpError if timeout during initial resuming and #{timeout_type} < retry_timeout" do
|
562 | 562 | stub_request(:get, "localhost/v1/next_uri").
|
563 | 563 | with(headers: headers).
|
564 | 564 | to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") })
|
565 | 565 |
|
566 |
| - lambda do |
| 566 | + expect do |
567 | 567 | StatementClient.new(faraday, query, options.merge(timeout_type => 2, retry_timeout: 1), "/v1/next_uri")
|
568 |
| - end.should raise_error(Trino::Client::TrinoHttpError, "Trino API error due to timeout") |
| 568 | + end.to raise_error(Trino::Client::TrinoHttpError, "Trino API error due to timeout") |
569 | 569 | end
|
570 | 570 | end
|
571 | 571 |
|
|
605 | 605 | stub_request(:get, "localhost/v1/next_uri").
|
606 | 606 | with(headers: headers).
|
607 | 607 | to_return(body: late_running_response.to_json)
|
608 |
| - lambda do |
| 608 | + expect do |
609 | 609 | client.advance
|
610 |
| - end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") |
| 610 | + end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") |
611 | 611 | end
|
612 | 612 |
|
613 | 613 | it "doesn't raise errors if query is done" do
|
|
0 commit comments