Permalink
Browse files

Handle queries that return no results without throwing an exception.

  • Loading branch information...
recurser committed Jul 16, 2015
1 parent 089259b commit 352e961f33f4b669f44c506d75b9a572356dfea1
Showing with 35 additions and 1 deletion.
  1. +1 −1 lib/influxdb/query/core.rb
  2. +34 −0 spec/influxdb/cases/query_core.rb
@@ -86,7 +86,7 @@ def execute(query, options = {})
end
def denormalize_series(series)
series["values"].map do |values|
Array(series["values"]).map do |values|
Hash[series["columns"].zip(values)]
end
end
@@ -0,0 +1,34 @@
require 'spec_helper'
require 'json'
describe InfluxDB::Client do
let(:subject) do
described_class.new(
'database',
{
host: 'influxdb.test',
port: 9999,
username: 'username',
password: 'password',
time_precision: 's'
}.merge(args)
)
end
let(:args) { {} }
describe '#query' do
it 'should handle responses with no values' do
# Some requests (such as trying to retrieve values from the future)
# return a result with no 'values' key set.
query = 'SELECT value FROM requests_per_minute WHERE time > 1437019900'
response = {'results'=>[{'series'=>[{'name'=>'requests_per_minute' ,'columns' => ['time','value']}]}]}
stub_request(:get, 'http://influxdb.test:9999/query').with(
query: { db: 'database', precision: 's', u: 'username', p: 'password', q: query }
).to_return(body: JSON.generate(response), status: 200)
expected_result = [{'name'=>'requests_per_minute', 'tags'=>nil, 'values'=>[]}]
expect(subject.query(query)).to eq(expected_result)
end
end
end

0 comments on commit 352e961

Please sign in to comment.