use super::store::F107Store;
use crate::data::bundled::{bundled_asset, BundledAssetMetadata};
use crate::error::{NsbError, Result};
use std::sync::OnceLock;
const RAW: &str = include_str!("../../data/f107_store.json");
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) const BUNDLED_F107_RELATIVE_PATH: &str = "f107_store.json";
#[cfg_attr(not(test), allow(dead_code))]
pub fn bundled_f107_asset() -> &'static BundledAssetMetadata {
bundled_asset(BUNDLED_F107_RELATIVE_PATH)
.expect("f107_store.json must be registered by the build script")
}
pub fn bundled_f107_store() -> Result<&'static F107Store> {
static STORE: OnceLock<std::result::Result<F107Store, String>> = OnceLock::new();
let loaded =
STORE.get_or_init(|| F107Store::from_json_str(RAW).map_err(|error| error.to_string()));
match loaded {
Ok(store) => Ok(store),
Err(message) => Err(NsbError::DataParse {
file: "data/f107_store.json",
message: message.clone(),
}),
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::solar_activity::store::hex_sha256;
#[test]
fn bundled_f107_metadata_matches_embedded_bytes() {
let asset = bundled_f107_asset();
assert_eq!(asset.path, BUNDLED_F107_RELATIVE_PATH);
assert_eq!(asset.schema, "nsb-f107-store-v1");
assert_eq!(hex_sha256(RAW.as_bytes()), asset.sha256);
assert!(!asset.source.is_empty());
assert!(!asset.validation_report.is_empty());
assert_eq!(asset.calibration_status, "planning-proxy");
}
}