test(influxdb_line_protocol): add value verification test (#5270)

pull/24376/head
Andrew Lamb 2022-08-02 07:18:09 -04:00 committed by GitHub
parent ee491cbbfc
commit 9c9658ca38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -1499,18 +1499,22 @@ mod test {
let input = "m0 field=-1.234456e06 1615869152385000000";
let vals = parse(input).unwrap();
assert_eq!(vals.len(), 1);
assert_float_field(&vals[0], "field", -1.234456e06);
let input = "m0 field=1.234456e06 1615869152385000000";
let vals = parse(input).unwrap();
assert_eq!(vals.len(), 1);
assert_float_field(&vals[0], "field", 1.234456e06);
let input = "m0 field=-1.234456E06 1615869152385000000";
let vals = parse(input).unwrap();
assert_eq!(vals.len(), 1);
assert_float_field(&vals[0], "field", -1.234456e06);
let input = "m0 field=1.234456E06 1615869152385000000";
let vals = parse(input).unwrap();
assert_eq!(vals.len(), 1);
assert_float_field(&vals[0], "field", 1.234456e06);
/////////////////////
// Negative tests
@ -2253,4 +2257,23 @@ her"#,
);
assert!(!FieldValue::Boolean(true).is_same_type(&FieldValue::U64(42)));
}
/// Assert that the field named `field_name` has a float value
/// within 0.0001% of `expected_value`, panic'ing if not
fn assert_float_field(parsed_line: &ParsedLine<'_>, field_name: &str, expected_value: f64) {
let field_value = parsed_line
.field_value(field_name)
.expect("did not contain field name");
let actual_value = if let FieldValue::F64(v) = field_value {
*v
} else {
panic!(
"field {} had value {:?}, expected F64",
field_name, field_value
);
};
assert!(approximately_equal(expected_value, actual_value));
}
}