influxdb-client 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +157 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.codecov.yml +3 -0
  5. data/.github/PULL_REQUEST_TEMPLATE +8 -0
  6. data/.gitignore +16 -0
  7. data/.rubocop.yml +38 -0
  8. data/CHANGELOG.md +27 -0
  9. data/Gemfile +24 -0
  10. data/LICENSE +21 -0
  11. data/README.md +248 -0
  12. data/Rakefile +37 -0
  13. data/bin/generate-sources.sh +23 -0
  14. data/bin/influxdb-onboarding.sh +39 -0
  15. data/bin/influxdb-restart.sh +60 -0
  16. data/bin/pom.xml +34 -0
  17. data/bin/swagger.yml +9867 -0
  18. data/influxdb-client.gemspec +53 -0
  19. data/lib/influxdb2/client.rb +29 -0
  20. data/lib/influxdb2/client/client.rb +89 -0
  21. data/lib/influxdb2/client/default_api.rb +87 -0
  22. data/lib/influxdb2/client/delete_api.rb +80 -0
  23. data/lib/influxdb2/client/flux_csv_parser.rb +251 -0
  24. data/lib/influxdb2/client/flux_table.rb +99 -0
  25. data/lib/influxdb2/client/influx_error.rb +31 -0
  26. data/lib/influxdb2/client/models/delete_predicate_request.rb +215 -0
  27. data/lib/influxdb2/client/models/dialect.rb +317 -0
  28. data/lib/influxdb2/client/models/query.rb +284 -0
  29. data/lib/influxdb2/client/point.rb +215 -0
  30. data/lib/influxdb2/client/query_api.rb +93 -0
  31. data/lib/influxdb2/client/version.rb +23 -0
  32. data/lib/influxdb2/client/worker.rb +115 -0
  33. data/lib/influxdb2/client/write_api.rb +243 -0
  34. data/test/influxdb/client_test.rb +70 -0
  35. data/test/influxdb/delete_api_integration_test.rb +100 -0
  36. data/test/influxdb/delete_api_test.rb +121 -0
  37. data/test/influxdb/flux_csv_parser_test.rb +401 -0
  38. data/test/influxdb/point_test.rb +221 -0
  39. data/test/influxdb/query_api_integration_test.rb +58 -0
  40. data/test/influxdb/query_api_stream_test.rb +98 -0
  41. data/test/influxdb/query_api_test.rb +96 -0
  42. data/test/influxdb/write_api_batching_test.rb +292 -0
  43. data/test/influxdb/write_api_integration_test.rb +76 -0
  44. data/test/influxdb/write_api_test.rb +275 -0
  45. data/test/test_helper.rb +39 -0
  46. metadata +214 -0
@@ -0,0 +1,221 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class PointTest < MiniTest::Test
24
+ def test_to_line_protocol
25
+ point_args = InfluxDB2::Point.new(name: 'h2o',
26
+ tags: { host: 'aws', region: 'us' },
27
+ fields: { level: 5, saturation: '99%' }, time: 123)
28
+ assert_equal 'h2o,host=aws,region=us level=5i,saturation="99%" 123', point_args.to_line_protocol
29
+
30
+ point_hash = InfluxDB2::Point.from_hash(name: 'h2o',
31
+ tags: { host: 'aws', region: 'us' },
32
+ fields: { level: 5, saturation: '99%' }, time: 123)
33
+ assert_equal 'h2o,host=aws,region=us level=5i,saturation="99%" 123', point_hash.to_line_protocol
34
+ end
35
+
36
+ def test_measurement_escape
37
+ point = InfluxDB2::Point.new(name: 'h2 o', tags: { location: 'europe' }, fields: { level: 2 })
38
+ assert_equal 'h2\\ o,location=europe level=2i', point.to_line_protocol
39
+
40
+ point = InfluxDB2::Point.new(name: 'h2,o', tags: { location: 'europe' }, fields: { level: 2 })
41
+ assert_equal 'h2\\,o,location=europe level=2i', point.to_line_protocol
42
+ end
43
+
44
+ def test_tag_empty_key
45
+ point = InfluxDB2::Point.new(name: 'h2o', fields: { level: 2 }).add_tag('location', 'europe').add_tag('', 'warn')
46
+
47
+ assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
48
+ end
49
+
50
+ def test_tag_empty_value
51
+ point = InfluxDB2::Point.new(name: 'h2o', fields: { level: 2 }).add_tag('location', 'europe').add_tag('log', '')
52
+
53
+ assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
54
+ end
55
+
56
+ def test_override_tag_and_field
57
+ point = InfluxDB2::Point.new(name: 'h2o', fields: { level: '1' })
58
+ .add_tag('location', 'europe')
59
+ .add_tag('location', 'europe2')
60
+ .add_field(:level, 2)
61
+ .add_field(:level, 3)
62
+
63
+ assert_equal 'h2o,location=europe2 level=3i', point.to_line_protocol
64
+ end
65
+
66
+ def test_field_types
67
+ point = InfluxDB2::Point.new(name: 'h2o')
68
+ .add_tag('tag_b', 'b')
69
+ .add_tag('tag_a', 'a')
70
+ .add_field('n1', -2)
71
+ .add_field('n2', 10)
72
+ .add_field('n3', 1_265_437_718_438_866_624_512)
73
+ .add_field('n4', 5.5)
74
+ .add_field('bool', true)
75
+ .add_field('string', 'string value')
76
+
77
+ expected = 'h2o,tag_a=a,tag_b=b bool=true,n1=-2i,n2=10i,n3=1265437718438866624512i,n4=5.5,string="string value"'
78
+ assert_equal expected, point.to_line_protocol
79
+ end
80
+
81
+ def test_field_null_value
82
+ point = InfluxDB2::Point.new(name: 'h2o')
83
+ .add_tag('location', 'europe')
84
+ .add_field('level', 2)
85
+ .add_field('warning', nil)
86
+
87
+ assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
88
+ end
89
+
90
+ def test_field_escape
91
+ point = InfluxDB2::Point.new(name: 'h2o')
92
+ .add_tag('location', 'europe')
93
+ .add_field('level', 'string esc\\ape value')
94
+
95
+ assert_equal 'h2o,location=europe level="string esc\\\\ape value"', point.to_line_protocol
96
+
97
+ point = InfluxDB2::Point.new(name: 'h2o')
98
+ .add_tag('location', 'europe')
99
+ .add_field('level', 'string esc"ape value')
100
+
101
+ assert_equal 'h2o,location=europe level="string esc\"ape value"', point.to_line_protocol
102
+ end
103
+
104
+ def test_time
105
+ point = InfluxDB2::Point.new(name: 'h2o')
106
+ .add_tag('location', 'europe')
107
+ .add_field('level', 2)
108
+ .time(123, InfluxDB2::WritePrecision::NANOSECOND)
109
+
110
+ assert_equal 'h2o,location=europe level=2i 123', point.to_line_protocol
111
+ end
112
+
113
+ def test_time_formatting
114
+ time = Time.utc(2015, 10, 15, 8, 20, 15)
115
+
116
+ point = InfluxDB2::Point.new(name: 'h2o')
117
+ .add_tag('location', 'europe')
118
+ .add_field('level', 2)
119
+ .time(time, InfluxDB2::WritePrecision::MILLISECOND)
120
+
121
+ assert_equal 'h2o,location=europe level=2i 1444897215000', point.to_line_protocol
122
+
123
+ point = InfluxDB2::Point.new(name: 'h2o')
124
+ .add_tag('location', 'europe')
125
+ .add_field('level', 2)
126
+ .time(time, InfluxDB2::WritePrecision::SECOND)
127
+
128
+ assert_equal 'h2o,location=europe level=2i 1444897215', point.to_line_protocol
129
+
130
+ point = InfluxDB2::Point.new(name: 'h2o')
131
+ .add_tag('location', 'europe')
132
+ .add_field('level', 2)
133
+ .time(time, InfluxDB2::WritePrecision::MICROSECOND)
134
+
135
+ assert_equal 'h2o,location=europe level=2i 1444897215000000', point.to_line_protocol
136
+
137
+ point = InfluxDB2::Point.new(name: 'h2o')
138
+ .add_tag('location', 'europe')
139
+ .add_field('level', 2)
140
+ .time(time, InfluxDB2::WritePrecision::NANOSECOND)
141
+
142
+ assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
143
+ end
144
+
145
+ def test_time_formatting_default
146
+ time = Time.utc(2015, 10, 15, 8, 20, 15)
147
+
148
+ point = InfluxDB2::Point.new(name: 'h2o', time: time)
149
+ .add_tag('location', 'europe')
150
+ .add_field('level', 2)
151
+
152
+ assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
153
+
154
+ point = InfluxDB2::Point.new(name: 'h2o')
155
+ .add_tag('location', 'europe')
156
+ .add_field('level', 2)
157
+ .time(time, nil)
158
+
159
+ assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
160
+ end
161
+
162
+ def test_time_string
163
+ point_args = InfluxDB2::Point.new(name: 'h2o',
164
+ tags: { host: 'aws', region: 'us' },
165
+ fields: { level: 5 }, time: '123')
166
+
167
+ assert_equal 'h2o,host=aws,region=us level=5i 123', point_args.to_line_protocol
168
+ end
169
+
170
+ def test_time_float
171
+ point_args = InfluxDB2::Point.new(name: 'h2o',
172
+ tags: { host: 'aws', region: 'us' },
173
+ fields: { level: 5 }, time: 1.444897215e+18)
174
+
175
+ assert_equal 'h2o,host=aws,region=us level=5i 1444897215000000000', point_args.to_line_protocol
176
+
177
+ point_args = InfluxDB2::Point.new(name: 'h2o',
178
+ tags: { host: 'aws', region: 'us' },
179
+ fields: { level: 5 }, time: 102_030_405_060)
180
+
181
+ assert_equal 'h2o,host=aws,region=us level=5i 102030405060', point_args.to_line_protocol
182
+ end
183
+
184
+ def test_utf_8
185
+ point = InfluxDB2::Point.new(name: 'h2o')
186
+ .add_tag('location', 'Přerov')
187
+ .add_field('level', 2)
188
+ .time(123, InfluxDB2::WritePrecision::NANOSECOND)
189
+
190
+ assert_equal 'h2o,location=Přerov level=2i 123', point.to_line_protocol
191
+ end
192
+
193
+ def test_infinity_values
194
+ point = InfluxDB2::Point.new(name: 'h2o')
195
+ .add_tag('location', 'europe')
196
+ .add_field('infinity_constant', Float::INFINITY)
197
+ .add_field('infinity_positive', 1 / 0.0)
198
+ .add_field('infinity_negative', -1 / 0.0)
199
+ .add_field('level', 2)
200
+
201
+ assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
202
+ end
203
+
204
+ def test_only_infinity_values
205
+ point = InfluxDB2::Point.new(name: 'h2o')
206
+ .add_tag('location', 'europe')
207
+ .add_field('infinity_constant', Float::INFINITY)
208
+ .add_field('infinity_positive', 1 / 0.0)
209
+ .add_field('infinity_negative', -1 / 0.0)
210
+
211
+ assert_nil point.to_line_protocol
212
+ end
213
+
214
+ def test_without_tags
215
+ point = InfluxDB2::Point.new(name: 'h2o')
216
+ .add_field('level', 2)
217
+ .time(123, InfluxDB2::WritePrecision::NANOSECOND)
218
+
219
+ assert_equal 'h2o level=2i 123', point.to_line_protocol
220
+ end
221
+ end
@@ -0,0 +1,58 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class QueryApiIntegrationTest < MiniTest::Test
24
+ def setup
25
+ WebMock.allow_net_connect!
26
+
27
+ @client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
28
+ bucket: 'my-bucket',
29
+ org: 'my-org',
30
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
31
+ use_ssl: false)
32
+ end
33
+
34
+ def test_query
35
+ now = Time.now.utc
36
+ measurement = 'h2o_query_' + now.to_i.to_s + now.nsec.to_s
37
+
38
+ @client.create_write_api.write(data: InfluxDB2::Point.new(name: measurement)
39
+ .add_tag('location', 'europe')
40
+ .add_field('level', 2)
41
+ .time(now, InfluxDB2::WritePrecision::NANOSECOND))
42
+
43
+ result = @client.create_query_api.query(query: 'from(bucket: "my-bucket") |> range(start: -1m, stop: now()) '\
44
+ "|> filter(fn: (r) => r._measurement == \"#{measurement}\")")
45
+
46
+ assert_equal 1, result.size
47
+
48
+ records = result[0].records
49
+ assert_equal 1, records.size
50
+
51
+ record = records[0]
52
+
53
+ assert_equal measurement, record.measurement
54
+ assert_equal 'europe', record.values['location']
55
+ assert_equal 2, record.value
56
+ assert_equal 'level', record.field
57
+ end
58
+ end
@@ -0,0 +1,98 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class QueryApiStreamTest < MiniTest::Test
24
+ def setup
25
+ WebMock.allow_net_connect!
26
+
27
+ @client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
28
+ bucket: 'my-bucket',
29
+ org: 'my-org',
30
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
31
+ use_ssl: false)
32
+ @now = Time.now.utc
33
+ end
34
+
35
+ def test_query_stream
36
+ measurement = 'h2o_query_stream' + @now.to_i.to_s + @now.nsec.to_s
37
+ _write(10, measurement: measurement)
38
+
39
+ query = 'from(bucket: "my-bucket") |> range(start: -1m, stop: now()) ' \
40
+ "|> filter(fn: (r) => r._measurement == \"#{measurement}\")"
41
+
42
+ count = 0
43
+ @client.create_query_api.query_stream(query: query).each do |record|
44
+ count += 1
45
+ assert_equal measurement, record.measurement
46
+ assert_equal 'europe', record.values['location']
47
+ assert_equal count, record.value
48
+ assert_equal 'level', record.field
49
+ end
50
+
51
+ assert_equal 10, count
52
+ end
53
+
54
+ def test_query_stream_break
55
+ measurement = 'h2o_query_stream_break' + @now.to_i.to_s + @now.nsec.to_s
56
+ _write(20, measurement: measurement)
57
+
58
+ query = 'from(bucket: "my-bucket") |> range(start: -1m, stop: now()) ' \
59
+ "|> filter(fn: (r) => r._measurement == \"#{measurement}\")"
60
+
61
+ records = []
62
+
63
+ parser = @client.create_query_api.query_stream(query: query)
64
+
65
+ assert_equal false, parser.closed
66
+
67
+ count = 0
68
+ parser.each do |record|
69
+ records.push(record)
70
+ count += 1
71
+
72
+ break if count >= 5
73
+ end
74
+
75
+ assert_equal 5, records.size
76
+ assert_equal true, parser.closed
77
+
78
+ # record 1
79
+ record = records[0]
80
+ assert_equal measurement, record.measurement
81
+ assert_equal 'europe', record.values['location']
82
+ assert_equal 1, record.value
83
+ assert_equal 'level', record.field
84
+ end
85
+
86
+ private
87
+
88
+ def _write(values, measurement:)
89
+ write_api = @client.create_write_api
90
+
91
+ (1..values).each do |value|
92
+ write_api.write(data: InfluxDB2::Point.new(name: measurement)
93
+ .add_tag('location', 'europe')
94
+ .add_field('level', value)
95
+ .time(@now - values + value, InfluxDB2::WritePrecision::NANOSECOND))
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,96 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class QueryApiTest < MiniTest::Test
24
+ def setup
25
+ WebMock.disable_net_connect!
26
+ end
27
+
28
+ SUCCESS_DATA = '#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,' \
29
+ "long,string,string,string,string\n" \
30
+ "#group,false,false,false,false,false,false,false,false,false,true\n" + "#default,_result,,,,,,,,,\n" \
31
+ ",result,table,_start,_stop,_time,_value,_field,_measurement,host,region\n" \
32
+ ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,10,free,mem,A,west\n" \
33
+ ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,20,free,mem,B,west\n" \
34
+ ",,0,1970-01-01T00:00:20Z,1970-01-01T00:00:30Z,1970-01-01T00:00:20Z,11,free,mem,A,west\n" \
35
+ ',,0,1970-01-01T00:00:20Z,1970-01-01T00:00:30Z,1970-01-01T00:00:20Z,22,free,mem,B,west'
36
+
37
+ def test_query_raw
38
+ stub_request(:post, 'http://localhost:9999/api/v2/query?org=my-org')
39
+ .to_return(body: SUCCESS_DATA)
40
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
41
+ bucket: 'my-bucket',
42
+ org: 'my-org',
43
+ use_ssl: false)
44
+
45
+ bucket = 'my-bucket'
46
+ result = client.create_query_api.query_raw(query:
47
+ 'from(bucket:"' + bucket + '") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
48
+
49
+ assert_equal result, SUCCESS_DATA
50
+ end
51
+
52
+ def test_query
53
+ stub_request(:post, 'http://localhost:9999/api/v2/query?org=my-org')
54
+ .to_return(body: SUCCESS_DATA)
55
+
56
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
57
+ bucket: 'my-bucket',
58
+ org: 'my-org',
59
+ use_ssl: false)
60
+
61
+ bucket = 'my-bucket'
62
+ result = client.create_query_api.query(query:
63
+ 'from(bucket:"' + bucket + '") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
64
+
65
+ assert_equal 1, result.length
66
+ assert_equal 4, result[0].records.length
67
+
68
+ record1 = result[0].records[0]
69
+
70
+ assert_equal Time.parse('1970-01-01T00:00:10Z').to_datetime.rfc3339, record1.time
71
+ assert_equal 'mem', record1.measurement
72
+ assert_equal 10, record1.value
73
+ assert_equal 'free', record1.field
74
+ end
75
+
76
+ def test_headers
77
+ stub_request(:post, 'http://localhost:9999/api/v2/query?org=my-org')
78
+ .to_return(body: SUCCESS_DATA)
79
+
80
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
81
+ bucket: 'my-bucket',
82
+ org: 'my-org',
83
+ use_ssl: false)
84
+
85
+ client.create_query_api
86
+ .query(query: 'from(bucket:"my-bucket") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
87
+
88
+ headers = {
89
+ 'Authorization' => 'Token my-token',
90
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
91
+ 'Content-Type' => 'application/json'
92
+ }
93
+ assert_requested(:post, 'http://localhost:9999/api/v2/query?org=my-org',
94
+ times: 1, headers: headers)
95
+ end
96
+ end