Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: name file restriction, changing :: for _ #249

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions api/tests/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,35 @@ impl JsonChecker for JsonCheckerImpl {
value: &T,
r#type: CheckType,
) -> bool {
let type_name = std::any::type_name::<T>().to_string();
let type_name = std::any::type_name::<T>().to_string().replace("::", "_");

let serialized_json =
serde_json::to_string_pretty(value).expect("Failed to serialize value");
let serialized_bson = bson::to_vec(value).expect("Failed to serialize value");

if self.r#override {
let bson_file_path = self.location() + &format!("/{}.bson", type_name);
let json_file_path = self.location() + &format!("/{}.json", type_name);

std::fs::write(json_file_path, serialized_json).expect("Failed to write JSON file");
std::fs::write(bson_file_path, serialized_bson).expect("Failed to write BSON file");
panic!("Override flag is enabled, remember to disable and commit the changes");
}

let file_path = match r#type {
CheckType::Json => self.location() + &format!("/{}.json", type_name),
CheckType::Bson => self.location() + &format!("/{}.bson", type_name),
};

match r#type {
CheckType::Json => {
let serialized =
serde_json::to_string_pretty(value).expect("Failed to serialize value");

let file = File::open(file_path.clone());

if self.r#override {
std::fs::write(file_path, serialized).expect("Failed to write to file");
std::fs::write(file_path, serialized_json).expect("Failed to write to file");
panic!("Override flag is enabled, remember to disable and commit the changes");
}

let file = File::open(file_path.clone());

if file.is_err() {
return false;
}
Expand All @@ -89,21 +100,14 @@ impl JsonChecker for JsonCheckerImpl {
let expected = serde_json::from_str::<T>(&contents)
.expect("Failed to deserialize expect value");

let actual = serde_json::from_str::<T>(&serialized)
let actual = serde_json::from_str::<T>(&serialized_json)
.expect("Failed to deserialize actual value");

expected == actual
}
CheckType::Bson => {
let serialized = bson::to_vec(value).expect("Failed to serialize value");

let file = File::open(file_path.clone());

if self.r#override {
std::fs::write(file_path, serialized).expect("Failed to write to file");
panic!("Override flag is enabled, remember to disable and commit the changes");
}

if file.is_err() {
return false;
}
Expand All @@ -118,8 +122,8 @@ impl JsonChecker for JsonCheckerImpl {
let expected =
bson::from_slice::<T>(&contents).expect("Failed to deserialize expect value");

let actual =
bson::from_slice::<T>(&serialized).expect("Failed to deserialize actual value");
let actual = bson::from_slice::<T>(&serialized_bson)
.expect("Failed to deserialize actual value");

expected == actual
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"expires_at": 100
}
},
"hasError": false,
"createdAt": 0,
"updatedAt": 0,
"updated": false,
Expand All @@ -47,4 +48,4 @@
"deleted": false,
"active": true,
"deprecated": false
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"fromCommonModel": "from-common-model",
"toCommonModel": "to-common-model"
},
"supported": false,
"createdAt": 0,
"updatedAt": 0,
"updated": false,
"version": "1.0.0",
"lastModifiedBy": "system",
"deleted": false,
"active": true,
"deprecated": false,
"supported": false
"deprecated": false
}
Loading