use satkit::jplephem;
use satkit::utils::datadir;
use satkit::{Instant, SolarSystem};
fn legacy_file_bytes() -> Option<Vec<u8>> {
let path = datadir().ok()?.join("linux_p1550p2650.440");
std::fs::read(path).ok()
}
#[test]
fn init_from_bytes_then_query_and_double_init_errors() {
let Some(bytes) = legacy_file_bytes() else {
eprintln!(
"skipping: linux_p1550p2650.440 not available in datadir(); \
run `python -m satkit.utils.update_datafiles` or set SATKIT_DATA"
);
return;
};
jplephem::init_from_bytes(&bytes).expect("init_from_bytes should succeed on first call");
let tm = Instant::from_datetime(2024, 3, 1, 12, 0, 0.0).unwrap();
let pos = jplephem::geocentric_pos(SolarSystem::Moon, &tm).expect("geocentric_pos");
let r = pos.norm();
assert!(
(3.0e8..5.0e8).contains(&r),
"Moon distance out of expected range: {r}"
);
let err = jplephem::init_from_bytes(&bytes)
.expect_err("second init_from_bytes should return AlreadyInitialized");
assert!(matches!(err, jplephem::Error::AlreadyInitialized));
}