forked from treasure-data/trino-client-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_spec.rb
75 lines (59 loc) · 1.92 KB
/
client_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'spec_helper'
describe Presto::Client::Client do
let(:client) { Presto::Client.new({}) }
describe 'rehashes' do
let(:columns) do
[
Models::Column.new(name: 'animal', type: 'string'),
Models::Column.new(name: 'score', type: 'integer'),
Models::Column.new(name: 'name', type: 'string')
]
end
it 'multiple rows' do
rows = [
['dog', 1, 'Lassie'],
['horse', 5, 'Mr. Ed'],
['t-rex', 37, 'Doug']
]
client.stub(:run).and_return([columns, rows])
rehashed = client.run_with_names('fake query')
rehashed.length.should == 3
rehashed[0]['animal'].should == 'dog'
rehashed[0]['score'].should == 1
rehashed[0]['name'].should == 'Lassie'
rehashed[0].values[0].should == 'dog'
rehashed[0].values[1].should == 1
rehashed[0].values[2].should == 'Lassie'
rehashed[1]['animal'].should == 'horse'
rehashed[1]['score'].should == 5
rehashed[1]['name'].should == 'Mr. Ed'
rehashed[1].values[0].should == 'horse'
rehashed[1].values[1].should == 5
rehashed[1].values[2].should == 'Mr. Ed'
end
it 'empty results' do
rows = []
client.stub(:run).and_return([columns, rows])
rehashed = client.run_with_names('fake query')
rehashed.length.should == 0
end
it 'handles too few result columns' do
rows = [['wrong', 'count']]
client.stub(:run).and_return([columns, rows])
client.run_with_names('fake query').should == [{
"animal" => "wrong",
"score" => "count",
"name" => nil,
}]
end
it 'handles too many result columns' do
rows = [['wrong', 'count', 'too', 'much', 'columns']]
client.stub(:run).and_return([columns, rows])
client.run_with_names('fake query').should == [{
"animal" => "wrong",
"score" => "count",
"name" => 'too',
}]
end
end
end