Add sandbox crate + workflow to test ephemeral podman runners
Build RPi image / build (push) Successful in 10s
Sandbox - ephemeral runner + shared cache / cargo (push) Failing after 2s

This commit is contained in:
druppy committed 2026-10-24 21:23:30 +02:00
1 parent 1c596cf097
commit 37d70c40c5
4 files changed
+314

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
//! Tiny crate used to exercise CI caching: enough deps to make a warm
//! build obviously faster than a cold one.
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Reading {
pub sensor: String,
pub celsius: f64,
}
pub fn to_fahrenheit(celsius: f64) -> f64 {
celsius * 9.0 / 5.0 + 32.0
}
pub fn parse(json: &str) -> Result<Reading> {
let r: Reading = serde_json::from_str(json)?;
if r.celsius < -273.15 {
bail!("{} C is below absolute zero", r.celsius);
}
Ok(r)
}
pub fn jitter(amount: f64) -> f64 {
use rand::Rng;
rand::thread_rng().gen_range(-amount..=amount)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn converts_units() {
assert!((to_fahrenheit(0.0) - 32.0).abs() < 1e-9);
assert!((to_fahrenheit(100.0) - 212.0).abs() < 1e-9);
}
#[test]
fn parses_reading() {
let r = parse(r#"{"sensor":"attic","celsius":21.5}"#).unwrap();
assert_eq!(r.sensor, "attic");
}
#[test]
fn rejects_impossible_temperature() {
assert!(parse(r#"{"sensor":"x","celsius":-300.0}"#).is_err());
}
}