|
| 1 | +require 'spec_helper' |
| 2 | +require 'telemetry/metrics/parser/line_protocol' |
| 3 | + |
| 4 | +RSpec.describe Telemetry::Metrics::Parser::LineProtocol do |
| 5 | + it 'can validate the measurement' do |
| 6 | + expect(described_class.measurement_valid?('foobar')).to eq true |
| 7 | + expect(described_class.measurement_valid?('FooBar')).to eq true |
| 8 | + expect(described_class.measurement_valid?('foo-bar')).to eq true |
| 9 | + expect(described_class.measurement_valid?('foo-bar_test')).to eq true |
| 10 | + expect(described_class.measurement_valid?('foo.test-bar_again')).to eq true |
| 11 | + end |
| 12 | + |
| 13 | + it 'can validate tags' do |
| 14 | + expect(described_class.tag_is_valid?('foobar', 'testing')).to eq true |
| 15 | + expect(described_class.tag_is_valid?('foo_bar', 'testing')).to eq true |
| 16 | + expect(described_class.tag_is_valid?('foo-bar', 'testing')).to eq true |
| 17 | + expect(described_class.tag_is_valid?('foo.bar', 'testing')).to eq true |
| 18 | + expect(described_class.tag_is_valid?('test', 'foo.bar')).to eq true |
| 19 | + expect(described_class.tag_is_valid?('test', 'foo-bar')).to eq true |
| 20 | + expect(described_class.tag_is_valid?('test', 'foo_bar')).to eq true |
| 21 | + expect(described_class.tag_is_valid?('test world', 'foo_bar')).to eq false |
| 22 | + expect(described_class.tag_is_valid?('test&world', 'foo_bar')).to eq false |
| 23 | + expect(described_class.tag_is_valid?('test', 'foo%bar')).to eq false |
| 24 | + end |
| 25 | + |
| 26 | + it 'can validate fields' do |
| 27 | + expect(described_class.field_is_number?(1)).to eq true |
| 28 | + expect(described_class.field_is_number?(0.11111)).to eq true |
| 29 | + expect(described_class.field_is_number?('foobar')).to eq false |
| 30 | + expect(described_class.field_is_number?('1i')).to eq true |
| 31 | + expect(described_class.field_is_number?('1f')).to eq true |
| 32 | + expect(described_class.field_is_number?('1.1f')).to eq true |
| 33 | + end |
| 34 | + |
| 35 | + it 'can validate the line is current' do |
| 36 | + expect(described_class.line_is_recent?(1_465_839_830_100_400_200)).to eq false |
| 37 | + expect(described_class.line_is_recent?(2_665_839_830_100_400_200)).to eq true |
| 38 | + expect(described_class.line_is_recent?('11111')).to eq false |
| 39 | + end |
| 40 | + |
| 41 | + it 'can verify a node_group tag exists' do |
| 42 | + expect(described_class.node_group_tag?({ foo: 'bar' })).to eq false |
| 43 | + expect(described_class.node_group_tag?({ influxdb_node_group: 'bar' })).to eq true |
| 44 | + end |
| 45 | + |
| 46 | + it 'can verify a database_tag exists' do |
| 47 | + expect(described_class.database_tag?({ foo: 'bar' })).to eq false |
| 48 | + expect(described_class.database_tag?({ influxdb_database: 'bar' })).to eq true |
| 49 | + end |
| 50 | + |
| 51 | + it 'can validate a line' do |
| 52 | + expect(described_class.line_is_valid?('weather,location=us-midwest temperature=82 1465839830100400200')).to be_a String |
| 53 | + expect(described_class.line_is_valid?('weather,location=us-midwest temperature=82 2465839830100400200')).to be_a String |
| 54 | + expect(described_class.line_is_valid?('weather,location=us-midwest,influxdb_database=foo temperature=82 2465839830100400200')).to be_a String |
| 55 | + expect(described_class.line_is_valid?('weather,location=us-midwest,influxdb_database=foo,influxdb_node_group=foo temperature=82 2465839830100400200')).to be_truthy |
| 56 | + expect(described_class.line_is_valid?('weather,location=us-midwest,influxdb_database=foo,influxdb_node_group=foo temperature=82,field=aaa 2465839830100400200')).to be_a String |
| 57 | + expect(described_class.line_is_valid?('weather,locat%ion=us-midw%est,influxdb_database=foo,influxdb_node_group=foo temperature=82 2465839830100400200')).to be_a String |
| 58 | + end |
| 59 | +end |
0 commit comments