Skip to content

Commit

Permalink
fix: name file restriction, changing :: for _ (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored Feb 17, 2025
1 parent 9a3f9a3 commit 0b4917a
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 20 deletions.
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
}

0 comments on commit 0b4917a

Please sign in to comment.