Skip to content

Commit 8e21dbf

Browse files
committed
add test-utils feature and update test code
1 parent 44c9377 commit 8e21dbf

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,12 @@ libc = "0.2.147"
361361
similar-asserts = "1.4.2"
362362
proptest = "1.2"
363363
quickcheck = "1.0.3"
364+
lookup = { package = "vector-lookup", path = "lib/vector-lookup", features = ["test"] }
364365
reqwest = { version = "0.11", features = ["json"] }
365366
tempfile = "3.6.0"
366367
test-generator = "0.3.1"
367-
tokio-test = "0.4.2"
368368
tokio = { version = "1.30.0", features = ["test-util"] }
369+
tokio-test = "0.4.2"
369370
tower-test = "0.4.0"
370371
vector-core = { path = "lib/vector-core", default-features = false, features = ["vrl", "test"] }
371372
wiremock = "0.5.19"

lib/vector-lookup/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ serde = { version = "1.0.183", default-features = false, features = ["derive", "
1111
vector-config = { path = "../vector-config" }
1212
vector-config-macros = { path = "../vector-config-macros" }
1313
vrl.workspace = true
14+
15+
[features]
16+
test = []

lib/vector-lookup/src/lookup_v2/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,10 @@ impl<'a> TargetPath<'a> for &'a ConfigTargetPath {
7070
&self.0.path
7171
}
7272
}
73+
74+
#[cfg(any(test, feature = "test"))]
75+
impl From<&str> for ConfigTargetPath {
76+
fn from(path: &str) -> Self {
77+
ConfigTargetPath::try_from(path.to_string()).unwrap()
78+
}
79+
}

src/transforms/dedupe.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn build_cache_entry(event: &Event, fields: &FieldMatchConfig) -> CacheEntry {
258258

259259
if let Some(all_fields) = event.as_log().all_fields() {
260260
for (field_name, value) in all_fields {
261-
if let Some(path) = ConfigTargetPath::try_from(field_name).ok() {
261+
if let Ok(path) = ConfigTargetPath::try_from(field_name) {
262262
if !fields.contains(&path) {
263263
entry.push((path, type_id_for_value(value), value.coerce_to_bytes()));
264264
}
@@ -288,6 +288,7 @@ impl TaskTransform<Event> for Dedupe {
288288
mod tests {
289289
use std::{collections::BTreeMap, sync::Arc};
290290

291+
use lookup::lookup_v2::ConfigTargetPath;
291292
use tokio::sync::mpsc;
292293
use tokio_stream::wrappers::ReceiverStream;
293294
use vector_common::config::ComponentKey;
@@ -308,7 +309,10 @@ mod tests {
308309
crate::test_util::test_generate_config::<DedupeConfig>();
309310
}
310311

311-
fn make_match_transform_config(num_events: usize, fields: Vec<String>) -> DedupeConfig {
312+
fn make_match_transform_config(
313+
num_events: usize,
314+
fields: Vec<ConfigTargetPath>,
315+
) -> DedupeConfig {
312316
DedupeConfig {
313317
cache: CacheConfig {
314318
num_events: std::num::NonZeroUsize::new(num_events).expect("non-zero num_events"),
@@ -317,7 +321,10 @@ mod tests {
317321
}
318322
}
319323

320-
fn make_ignore_transform_config(num_events: usize, given_fields: Vec<String>) -> DedupeConfig {
324+
fn make_ignore_transform_config(
325+
num_events: usize,
326+
given_fields: Vec<ConfigTargetPath>,
327+
) -> DedupeConfig {
321328
// "message" and "timestamp" are added automatically to all Events
322329
let mut fields = vec!["message".into(), "timestamp".into()];
323330
fields.extend(given_fields);

0 commit comments

Comments
 (0)