blob: 160c6b5d870bab6d011f2066c4bc4ac3b132ac16 [file] [log] [blame]
Éric Lemoine71272712016-11-08 12:53:51 +00001-- 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
15EXPORT_ASSERT_TO_GLOBALS=true
16require('luaunit')
17require('os')
18package.path = package.path .. ";../heka/files/lua/common/?.lua;lua/mocks/?.lua"
19
20local influxdb = require('influxdb')
21
22TestInfluxDB = {}
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
48lu = LuaUnit
49lu:setVerbosity( 1 )
50os.exit( lu:run() )
51
52