mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-23 21:26:26 +00:00
Add redaction system
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
use anyhow::Context;
|
||||
use cargo_metadata::semver::Version;
|
||||
use chrono::DateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
@ -29,6 +31,29 @@ enum CommandOrUpgradeVec<'a> {
|
||||
Upgrade(VersionOrLatest),
|
||||
}
|
||||
|
||||
fn produce_reference_value(value: &mut Value) {
|
||||
match value {
|
||||
Value::Null | Value::Bool(_) | Value::Number(_) => (),
|
||||
Value::String(string) => {
|
||||
if DateTime::parse_from_rfc3339(string.as_str()).is_ok() {
|
||||
*string = String::from("[timestamp]");
|
||||
} else if uuid::Uuid::parse_str(string).is_ok() {
|
||||
*string = String::from("[uuid]");
|
||||
}
|
||||
}
|
||||
Value::Array(values) => {
|
||||
for value in values {
|
||||
produce_reference_value(value);
|
||||
}
|
||||
}
|
||||
Value::Object(map) => {
|
||||
for (_key, value) in map.iter_mut() {
|
||||
produce_reference_value(value);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// A test workload.
|
||||
/// Not to be confused with [a bench workload](crate::bench::workload::Workload).
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@ -104,11 +129,12 @@ impl TestWorkload {
|
||||
.await?;
|
||||
if return_responses {
|
||||
assert_eq!(responses.len(), cloned.len());
|
||||
for (command, (response, status)) in commands.into_iter().zip(responses) {
|
||||
for (command, (mut response, status)) in commands.into_iter().zip(responses) {
|
||||
if args.update_responses
|
||||
|| (dbg!(args.add_missing_responses)
|
||||
&& dbg!(command.expected_response.is_none()))
|
||||
{
|
||||
produce_reference_value(&mut response);
|
||||
command.expected_response = Some(response);
|
||||
command.expected_status = Some(status.as_u16());
|
||||
}
|
||||
|
Reference in New Issue
Block a user