Éric Lemoine | 7127271 | 2016-11-08 12:53:51 +0000 | [diff] [blame] | 1 | -- Copyright 2016 Mirantis, Inc. |
| 2 | -- |
| 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | -- you may not use this file except in compliance with the License. |
| 5 | -- You may obtain a copy of the License at |
| 6 | -- |
| 7 | -- http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | -- |
| 9 | -- Unless required by applicable law or agreed to in writing, software |
| 10 | -- distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | -- See the License for the specific language governing permissions and |
| 13 | -- limitations under the License. |
| 14 | |
| 15 | EXPORT_ASSERT_TO_GLOBALS=true |
| 16 | require('luaunit') |
| 17 | require('os') |
| 18 | package.path = package.path .. ";../heka/files/lua/common/?.lua;lua/mocks/?.lua" |
| 19 | |
| 20 | local influxdb = require('influxdb') |
| 21 | |
| 22 | TestInfluxDB = {} |
| 23 | |
| 24 | function TestInfluxDB:test_ms_precision_encoder() |
| 25 | local encoder = influxdb.new("ms") |
| 26 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1), 'foo value=1.000000 1000000') |
| 27 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 'bar'), 'foo value="bar" 1000000') |
| 28 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 'b"ar'), 'foo value="b\\"ar" 1000000') |
| 29 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1, {tag2="t2",tag1="t1"}), 'foo,tag1=t1,tag2=t2 value=1.000000 1000000') |
| 30 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', {a=1, b=2}), 'foo a=1.000000,b=2.000000 1000000') |
| 31 | end |
| 32 | |
| 33 | function TestInfluxDB:test_second_precision_encoder() |
| 34 | local encoder = influxdb.new("s") |
| 35 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1), 'foo value=1.000000 1000') |
| 36 | end |
| 37 | |
| 38 | function TestInfluxDB:test_us_precision_encoder() |
| 39 | local encoder = influxdb.new("us") |
| 40 | assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1), 'foo value=1.000000 1000000000') |
| 41 | end |
| 42 | |
| 43 | function TestInfluxDB:test_encoder_with_bad_input() |
| 44 | local encoder = influxdb.new() |
| 45 | assertEquals(encoder:encode_datapoint(1e9 * 1000, nil, 1), '') |
| 46 | end |
| 47 | |
| 48 | lu = LuaUnit |
| 49 | lu:setVerbosity( 1 ) |
| 50 | os.exit( lu:run() ) |
| 51 | |
| 52 | |