Skip to content

Commit

Permalink
test(filemanager): remove some repetitive code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalenic committed Mar 6, 2024
1 parent 30fab49 commit d4b04ed
Showing 1 changed file with 146 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1195,171 +1195,157 @@ pub(crate) mod tests {

// 720 permutations
run_permutation_test(&pool, event_permutations, 5, |s3_object_results| {
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id")
== FlatS3EventMessage::default_version_id()
&& object.get::<Option<String>, _>("created_sequencer")
== Some("1".to_string())
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("2".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id")
== FlatS3EventMessage::default_version_id()
&& object
.get::<Option<String>, _>("created_sequencer")
.is_none()
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("3".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id")
== FlatS3EventMessage::default_version_id()
&& object.get::<Option<String>, _>("created_sequencer")
== Some("4".to_string())
&& object
.get::<Option<String>, _>("deleted_sequencer")
.is_none()
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id")
== FlatS3EventMessage::default_version_id()
&& object.get::<Option<String>, _>("created_sequencer")
== Some("5".to_string())
&& object
.get::<Option<String>, _>("deleted_sequencer")
.is_none()
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key1"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id")
== FlatS3EventMessage::default_version_id()
&& object.get::<Option<String>, _>("created_sequencer")
== Some("1".to_string())
&& object
.get::<Option<String>, _>("deleted_sequencer")
.is_none()
})
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
&FlatS3EventMessage::default_version_id(),
Some("1"),
Some("2"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
&FlatS3EventMessage::default_version_id(),
None,
Some("3"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
&FlatS3EventMessage::default_version_id(),
Some("4"),
None,
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
&FlatS3EventMessage::default_version_id(),
Some("5"),
None,
)
.unwrap();
find_object_with(
&s3_object_results,
"key1",
"bucket",
&FlatS3EventMessage::default_version_id(),
Some("1"),
None,
)
.unwrap();
})
.await;
}

#[sqlx::test(migrator = "MIGRATOR")]
async fn ingest_permutations_small(pool: PgPool) {
let event_permutations = vec![
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Created)
.with_sequencer(Some("1".to_string())),
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Deleted)
.with_sequencer(Some("2".to_string())),
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Created)
.with_sequencer(Some("3".to_string())),
// Duplicate
let event_permutations = example_event_permutations();

// 720 permutations
run_permutation_test(&pool, event_permutations, 3, |s3_object_results| {
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id",
Some("1"),
Some("2"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id",
Some("3"),
Some("4"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id1",
None,
Some("1"),
)
.unwrap();
})
.await;
}

#[ignore]
#[sqlx::test(migrator = "MIGRATOR")]
async fn ingest_permutations(pool: PgPool) {
// This primarily tests out of order and duplicate event ingestion, however it could also function
// as a performance test.
let mut event_permutations = example_event_permutations();
event_permutations.extend(vec![
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Created)
.with_sequencer(Some("3".to_string())),
.with_sequencer(Some("5".to_string())),
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Deleted)
.with_sequencer(Some("4".to_string())),
// Different version id
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id1".to_string())
.with_event_type(Deleted)
.with_sequencer(Some("1".to_string())),
];
.with_sequencer(Some("6".to_string())),
]);

// 720 permutations
run_permutation_test(&pool, event_permutations, 3, |s3_object_results| {
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id"
&& object.get::<Option<String>, _>("created_sequencer")
== Some("1".to_string())
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("2".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id"
&& object.get::<Option<String>, _>("created_sequencer")
== Some("3".to_string())
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("4".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id1"
&& object
.get::<Option<String>, _>("created_sequencer")
.is_none()
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("1".to_string())
})
.unwrap();
// 40320 permutations
run_permutation_test(&pool, event_permutations, 4, |s3_object_results| {
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id",
Some("1"),
Some("2"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id",
Some("3"),
Some("4"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id",
Some("5"),
Some("6"),
)
.unwrap();
find_object_with(
&s3_object_results,
"key",
"bucket",
"version_id1",
None,
Some("1"),
)
.unwrap();
})
.await;
}

#[ignore]
#[sqlx::test(migrator = "MIGRATOR")]
async fn ingest_permutations(pool: PgPool) {
// This primarily tests out of order and duplicate event ingestion, however it could also function
// as a performance test.
let event_permutations = vec![
fn example_event_permutations() -> Vec<FlatS3EventMessage> {
vec![
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
Expand Down Expand Up @@ -1391,80 +1377,31 @@ pub(crate) mod tests {
.with_version_id("version_id".to_string())
.with_event_type(Deleted)
.with_sequencer(Some("4".to_string())),
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Created)
.with_sequencer(Some("5".to_string())),
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id".to_string())
.with_event_type(Deleted)
.with_sequencer(Some("6".to_string())),
// Different version id
FlatS3EventMessage::new_with_generated_id()
.with_bucket("bucket".to_string())
.with_key("key".to_string())
.with_version_id("version_id1".to_string())
.with_event_type(Deleted)
.with_sequencer(Some("1".to_string())),
];
]
}

// 40320 permutations
run_permutation_test(&pool, event_permutations, 4, |s3_object_results| {
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id"
&& object.get::<Option<String>, _>("created_sequencer")
== Some("1".to_string())
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("2".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id"
&& object.get::<Option<String>, _>("created_sequencer")
== Some("3".to_string())
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("4".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id"
&& object.get::<Option<String>, _>("created_sequencer")
== Some("5".to_string())
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("6".to_string())
})
.unwrap();
s3_object_results
.iter()
.find(|object| {
object.get::<String, _>("key") == "key"
&& object.get::<String, _>("bucket") == "bucket"
&& object.get::<String, _>("version_id") == *"version_id1"
&& object
.get::<Option<String>, _>("created_sequencer")
.is_none()
&& object.get::<Option<String>, _>("deleted_sequencer")
== Some("1".to_string())
})
.unwrap();
fn find_object_with<'a>(
results: &'a [PgRow],
key: &str,
bucket: &str,
version_id: &str,
created_sequencer: Option<&str>,
deleted_sequencer: Option<&str>,
) -> Option<&'a PgRow> {
results.iter().find(|object| {
object.get::<String, _>("key") == key
&& object.get::<String, _>("bucket") == bucket
&& object.get::<String, _>("version_id") == version_id
&& object.get::<Option<&str>, _>("created_sequencer") == created_sequencer
&& object.get::<Option<&str>, _>("deleted_sequencer") == deleted_sequencer
})
.await;
}

async fn run_permutation_test<F>(
Expand Down

0 comments on commit d4b04ed

Please sign in to comment.