Cotton code
18 lines · 1.5 KB · RustRaw
use cotton_store::{driver::Driver, schema::{ddl::DEVICES_TABLE, decl::Codec}};use rusqlite::types::Value;/// RULE: The device floor is nullable integer bytes, born NULL for the volume default, and rejects negative values so every consumer can trust the same synced setting.#[test]fn the_device_keep_free_setting_is_nullable_nonnegative_integer_bytes() {    let db = Driver::open_in_memory().unwrap();    db.exec("CREATE TABLE cotton_workspaces (id TEXT PRIMARY KEY); INSERT INTO cotton_workspaces VALUES ('synthetic');").unwrap();    db.exec(DEVICES_TABLE).unwrap();    db.exec("INSERT INTO cotton_devices (id,workspace_id,device_id,name,approved_at,approved_by_device,created_at,updated_at) VALUES ('device','synthetic','key','Synthetic Mac','now','key','now','now')").unwrap();    assert_eq!(db.get("SELECT keep_free_bytes FROM cotton_devices", &[]).unwrap().unwrap().int("keep_free_bytes"), None);    db.run("UPDATE cotton_devices SET keep_free_bytes=?", &[Value::Integer(100_000_000_000)]).unwrap();    assert_eq!(db.get("SELECT keep_free_bytes FROM cotton_devices", &[]).unwrap().unwrap().int("keep_free_bytes"), Some(100_000_000_000));    assert!(db.run("UPDATE cotton_devices SET keep_free_bytes=?", &[Value::Integer(-1)]).is_err());    let spec = cotton_store::schema::specs::spec_for("cotton_devices").unwrap();    assert_eq!(spec.columns.iter().find(|(name,_)| *name=="keep_free_bytes").unwrap().1, Codec::Int);    assert_eq!(spec.columns.iter().find(|(name,_)| *name=="takes_placements").unwrap().1, Codec::Bool);}