Skip to content

Commit

Permalink
add test-utils feature and update test code
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Aug 15, 2023
1 parent 9683a1d commit 014b865
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,12 @@ libc = "0.2.147"
similar-asserts = "1.4.2"
proptest = "1.2"
quickcheck = "1.0.3"
lookup = { package = "vector-lookup", path = "lib/vector-lookup", features = ["test"] }
reqwest = { version = "0.11", features = ["json"] }
tempfile = "3.6.0"
test-generator = "0.3.1"
tokio-test = "0.4.2"
tokio = { version = "1.30.0", features = ["test-util"] }
tokio-test = "0.4.2"
tower-test = "0.4.0"
vector-core = { path = "lib/vector-core", default-features = false, features = ["vrl", "test"] }
wiremock = "0.5.19"
Expand Down
3 changes: 3 additions & 0 deletions lib/vector-lookup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ serde = { version = "1.0.183", default-features = false, features = ["derive", "
vector-config = { path = "../vector-config" }
vector-config-macros = { path = "../vector-config-macros" }
vrl.workspace = true

[features]
test = []
7 changes: 7 additions & 0 deletions lib/vector-lookup/src/lookup_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ impl<'a> TargetPath<'a> for &'a ConfigTargetPath {
&self.0.path
}
}

#[cfg(any(test, feature = "test"))]
impl From<&str> for ConfigTargetPath {
fn from(path: &str) -> Self {
ConfigTargetPath::try_from(path.to_string()).unwrap()
}
}
13 changes: 10 additions & 3 deletions src/transforms/dedupe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn build_cache_entry(event: &Event, fields: &FieldMatchConfig) -> CacheEntry {

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

use lookup::lookup_v2::ConfigTargetPath;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use vector_common::config::ComponentKey;
Expand All @@ -308,7 +309,10 @@ mod tests {
crate::test_util::test_generate_config::<DedupeConfig>();
}

fn make_match_transform_config(num_events: usize, fields: Vec<String>) -> DedupeConfig {
fn make_match_transform_config(
num_events: usize,
fields: Vec<ConfigTargetPath>,
) -> DedupeConfig {
DedupeConfig {
cache: CacheConfig {
num_events: std::num::NonZeroUsize::new(num_events).expect("non-zero num_events"),
Expand All @@ -317,7 +321,10 @@ mod tests {
}
}

fn make_ignore_transform_config(num_events: usize, given_fields: Vec<String>) -> DedupeConfig {
fn make_ignore_transform_config(
num_events: usize,
given_fields: Vec<ConfigTargetPath>,
) -> DedupeConfig {
// "message" and "timestamp" are added automatically to all Events
let mut fields = vec!["message".into(), "timestamp".into()];
fields.extend(given_fields);
Expand Down

0 comments on commit 014b865

Please sign in to comment.