Skip to content

Commit

Permalink
refactor: apply linter's advices
Browse files Browse the repository at this point in the history
Signed-off-by: David Bernard <david.bernard.31@gmail.com>
  • Loading branch information
davidB committed Mar 3, 2024
1 parent f3f353b commit 4d183fa
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cdevents-sdk/tests/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@ impl EventsSchemas {
let ty = jsonschema["properties"]["context"]["properties"]["type"]["default"].as_str()
.unwrap_or_default()
.to_string();
if !mapping.contains_key(&ty) {
mapping.entry(ty).or_insert_with(|| {
let sch_index = compiler.compile(&schemapath.to_string_lossy(), &mut schemas);
if let Err(err) = sch_index {
panic!("{err:#}"); //like a assert(false,...)
}
let sch_index = sch_index.unwrap();
mapping.insert(ty, sch_index);
}
sch_index.unwrap()
});
}
Self {
schemas, mapping
}
}

fn check_against_schema(&self, json: &serde_json::Value, ty: &str) {
let sch_index = self.mapping.get(ty).expect(&format!("to have schema for {ty}"));
let result = self.schemas.validate(json, sch_index.clone());
let sch_index = self.mapping.get(ty).unwrap_or_else(|| panic!("to have schema for {ty}"));
let result = self.schemas.validate(json, *sch_index);
if let Err(err) = result {
panic!("{err}");
}
Expand All @@ -51,7 +50,7 @@ impl EventsSchemas {
static EVENTS_SCHEMA_CELL: OnceLock<EventsSchemas> = OnceLock::new();

fn events_schemas() -> &'static EventsSchemas {
EVENTS_SCHEMA_CELL.get_or_init(|| EventsSchemas::load())
EVENTS_SCHEMA_CELL.get_or_init(EventsSchemas::load)
}

#[rstest]
Expand Down

0 comments on commit 4d183fa

Please sign in to comment.