Skip to content

Commit 44200d1

Browse files
committed
Use serde_json value for structure checks at comptime
1 parent 40e4076 commit 44200d1

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

pilatus-axum-rt/tests/import_export_with_web.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ fn upload_zip() -> anyhow::Result<()> {
4242
});
4343
}
4444
TempRuntime::new()
45-
.config_json(
46-
br#"{
45+
.config(serde_json::json!({
4746
"web": {
4847
"socket": "0.0.0.0:0"
4948
},
@@ -59,8 +58,7 @@ fn upload_zip() -> anyhow::Result<()> {
5958
"tower_http": "trace"
6059
}
6160
}
62-
}"#,
63-
)
61+
}))
6462
.register(pilatus_axum_rt::register)
6563
.register(register_test_services)
6664
.configure()?

pilatus-emulation-camera-rt/tests/record.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ fn record_integration() -> anyhow::Result<()> {
88
use serde_json::json;
99

1010
let configured = TempRuntime::new()
11-
.config_json(
12-
br#"{
11+
.config(serde_json::json!({
1312
"web": {
1413
"socket": "0.0.0.0:0"
1514
},
@@ -20,8 +19,7 @@ fn record_integration() -> anyhow::Result<()> {
2019
"pilatus::image": "debug"
2120
}
2221
}
23-
}"#,
24-
)
22+
}))
2523
.register(pilatus_engineering_rt::register)
2624
.register(pilatus_axum_rt::register)
2725
.register(pilatus_emulation_camera_rt::register)

pilatus-emulation-camera-rt/tests/stop_streaming.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ fn stops_streaming_when_all_subscribers_are_gone() -> anyhow::Result<()> {
3232
}
3333

3434
let configured = TempRuntime::new()
35-
.config_json(br#"{ "web": { "socket": "0.0.0.0:0" } }"#)
35+
.config(serde_json::json!({
36+
"web": { "socket": "0.0.0.0:0" }
37+
}))
3638
.register(pilatus_emulation_camera_rt::register)
3739
.register(pilatus_engineering_rt::register)
3840
.register(pilatus_axum_rt::register)

pilatus-emulation-camera-rt/tests/upload_image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn upload_image_to_collection() -> anyhow::Result<()> {
88
use serde_json::json;
99

1010
let configured = TempRuntime::new()
11-
.config_json(br#"{ "web": { "socket": "0.0.0.0:0" } }"#)
11+
.config(serde_json::json!({ "web": { "socket": "0.0.0.0:0" } }))
1212
.register(pilatus_emulation_camera_rt::register)
1313
.register(pilatus_engineering_rt::register)
1414
.register(pilatus_axum_rt::register)

pilatus-rt/src/runtime.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use tokio::runtime::Builder;
99
use tracing::{error, info};
1010

1111
use pilatus::{GenericConfig, HostedService, SystemTerminator};
12+
use serde_json::Value as JsonValue;
1213

1314
use crate::metadata_future::MetadataFuture;
1415

@@ -21,7 +22,7 @@ pub struct Runtime {
2122
/// Convenience wrapper for integration tests.
2223
/// Keeps the temporary directory alive for as long as the runtime is used.
2324
pub struct TempRuntime {
24-
config_json: Option<Vec<u8>>,
25+
config_json: Option<JsonValue>,
2526
steps: Vec<TempRuntimeStep>,
2627
}
2728

@@ -40,8 +41,8 @@ impl TempRuntime {
4041
}
4142

4243
/// Sets the `config.json` contents to be written during [`TempRuntime::configure`].
43-
pub fn config_json(mut self, config_json: impl AsRef<[u8]>) -> Self {
44-
self.config_json = Some(config_json.as_ref().to_vec());
44+
pub fn config(mut self, config_json: JsonValue) -> Self {
45+
self.config_json = Some(config_json);
4546
self
4647
}
4748

@@ -66,6 +67,8 @@ impl TempRuntime {
6667
pub fn configure(self) -> Result<TempConfiguredRuntime, std::io::Error> {
6768
let dir = tempfile::tempdir()?;
6869
if let Some(cfg) = self.config_json {
70+
let cfg = serde_json::to_vec(&cfg)
71+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
6972
std::fs::write(dir.path().join("config.json"), cfg)?;
7073
}
7174

0 commit comments

Comments
 (0)