Skip to content

Commit 7d4f30a

Browse files
committed
Use pretty formatting for parsed sub-json
1 parent 2f42cb8 commit 7d4f30a

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

internal/mithril-build-script/src/fake_aggregator.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn extract_artifact_id_and_content(
186186
key: &String,
187187
value: &serde_json::Value,
188188
) -> Result<(ArtifactId, FileContent), String> {
189-
let json_content = serde_json::to_string(value).map_err(|e| e.to_string())?;
189+
let json_content = serde_json::to_string_pretty(value).map_err(|e| e.to_string())?;
190190
Ok((key.to_owned(), json_content))
191191
}
192192

@@ -327,22 +327,36 @@ fn b() {}
327327
}
328328

329329
#[test]
330-
fn read_artifacts_json_file() {
330+
fn parse_artifacts_json_into_btree_of_key_and_pretty_sub_json() {
331331
let dir = get_temp_dir("read_artifacts_json_file");
332332
let file = dir.join("test.json");
333-
let json_content = r#"{
333+
fs::write(
334+
&file,
335+
r#"{
334336
"hash1": { "name": "artifact1" },
335337
"hash2": { "name": "artifact2" }
336-
}"#;
337-
let expected = BTreeMap::from([
338-
("hash1".to_string(), r#"{"name":"artifact1"}"#.to_string()),
339-
("hash2".to_string(), r#"{"name":"artifact2"}"#.to_string()),
340-
]);
341-
342-
fs::write(&file, json_content).unwrap();
338+
}"#,
339+
)
340+
.unwrap();
343341

344342
let id_per_json = FakeAggregatorData::read_artifacts_json_file(&file);
345343

344+
let expected = BTreeMap::from([
345+
(
346+
"hash1".to_string(),
347+
r#"{
348+
"name": "artifact1"
349+
}"#
350+
.to_string(),
351+
),
352+
(
353+
"hash2".to_string(),
354+
r#"{
355+
"name": "artifact2"
356+
}"#
357+
.to_string(),
358+
),
359+
]);
346360
assert_eq!(expected, id_per_json);
347361
}
348362
}

0 commit comments

Comments
 (0)