blob: 73d650dbe151b4bf3ac88c833ebf567dd3122b34 [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
Simon Pasquierc04539d2017-03-24 14:27:53 +010024 function TestInfluxDB:test_escaping_characters()
25 local encoder = influxdb.new("s")
26 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 2, {tag1='"tag1"'}), 'foo,tag1=tag1 value=2.000000 1000')
27 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 2, {tag1=",tag 1="}), 'foo,tag1=\\,tag\\ 1\\= value=2.000000 1000')
28 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 'b"ar'), 'foo value="b\\"ar" 1000')
29 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', true), 'foo value=true 1000')
30 end
31
Éric Lemoine71272712016-11-08 12:53:51 +000032 function TestInfluxDB:test_ms_precision_encoder()
33 local encoder = influxdb.new("ms")
34 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1), 'foo value=1.000000 1000000')
35 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 'bar'), 'foo value="bar" 1000000')
Éric Lemoine71272712016-11-08 12:53:51 +000036 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1, {tag2="t2",tag1="t1"}), 'foo,tag1=t1,tag2=t2 value=1.000000 1000000')
37 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', {a=1, b=2}), 'foo a=1.000000,b=2.000000 1000000')
38 end
39
40 function TestInfluxDB:test_second_precision_encoder()
41 local encoder = influxdb.new("s")
42 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1), 'foo value=1.000000 1000')
43 end
44
45 function TestInfluxDB:test_us_precision_encoder()
46 local encoder = influxdb.new("us")
47 assertEquals(encoder:encode_datapoint(1e9 * 1000, 'foo', 1), 'foo value=1.000000 1000000000')
48 end
49
50 function TestInfluxDB:test_encoder_with_bad_input()
51 local encoder = influxdb.new()
52 assertEquals(encoder:encode_datapoint(1e9 * 1000, nil, 1), '')
53 end
54
55lu = LuaUnit
56lu:setVerbosity( 1 )
57os.exit( lu:run() )
58
59