Lines Matching refs:db
86 let mut db = Self { in new_at_path() localVariable
92 db.init_tables().context("failed to create tables")?; in new_at_path()
95 match db.schema_version() { in new_at_path()
109 Ok(0) => db.upgrade_tables_v0_v1().context("failed to upgrade schema v0 -> v1")?, in new_at_path()
121 Ok((db, created)) in new_at_path()
379 let mut db = VmIdDb { conn: Connection::open_in_memory().unwrap() }; in new_test_db_version() localVariable
381 0 => db.init_tables_v0().unwrap(), in new_test_db_version()
382 1 => db.init_tables_v1().unwrap(), in new_test_db_version()
385 db in new_test_db_version()
388 fn show_contents(db: &VmIdDb) { in show_contents()
389 let mut stmt = db.conn.prepare("SELECT * FROM main.vmids;").unwrap(); in show_contents()
397 fn show_contents_for_app(db: &VmIdDb, user_id: i32, app_id: i32, count: usize) { in show_contents_for_app()
398 let mut stmt = db in show_contents_for_app()
427 let mut db = new_test_db_version(0); in test_schema_upgrade_v0_v1() localVariable
428 let version = db.schema_version().unwrap(); in test_schema_upgrade_v0_v1()
432 db.conn in test_schema_upgrade_v0_v1()
439 db.upgrade_tables_v0_v1().unwrap(); in test_schema_upgrade_v0_v1()
440 let version = db.schema_version().unwrap(); in test_schema_upgrade_v0_v1()
443 assert_eq!(vec![VM_ID1], db.vm_ids_for_user(USER1).unwrap()); in test_schema_upgrade_v0_v1()
444 show_contents(&db); in test_schema_upgrade_v0_v1()
458 let (mut db, created) = in test_corrupt_database_file()
461 db.add_vm_id(&VM_ID1, USER1, APP_A).unwrap(); in test_corrupt_database_file()
462 assert_eq!(vec![VM_ID1], db.vm_ids_for_user(USER1).unwrap()); in test_corrupt_database_file()
472 let (db, created) = VmIdDb::new(&db_dir.path().to_string_lossy()).unwrap(); in test_non_upgradable_database_file()
474 db.conn.execute("DROP TABLE main.vmids", ()).unwrap(); in test_non_upgradable_database_file()
475 db.conn.execute("PRAGMA main.user_version = 0;", ()).unwrap(); in test_non_upgradable_database_file()
487 let (mut db, created) = VmIdDb::new(&db_dir.path().to_string_lossy()).unwrap(); in test_database_from_the_future()
489 db.add_vm_id(&VM_ID1, USER1, APP_A).unwrap(); in test_database_from_the_future()
491 db.conn.execute("PRAGMA main.user_version = 99;", ()).unwrap(); in test_database_from_the_future()
500 let mut db = new_test_db(); in test_add_remove() localVariable
501 db.add_vm_id(&VM_ID1, USER1, APP_A).unwrap(); in test_add_remove()
502 db.add_vm_id(&VM_ID2, USER1, APP_A).unwrap(); in test_add_remove()
503 db.add_vm_id(&VM_ID3, USER1, APP_A).unwrap(); in test_add_remove()
504 db.add_vm_id(&VM_ID4, USER2, APP_B).unwrap(); in test_add_remove()
505 db.add_vm_id(&VM_ID5, USER3, APP_A).unwrap(); in test_add_remove()
506 db.add_vm_id(&VM_ID5, USER3, APP_C).unwrap(); // Overwrites APP_A in test_add_remove()
510 db.get_all_owners().unwrap() in test_add_remove()
515 assert_eq!(vec![VM_ID1, VM_ID2, VM_ID3], db.vm_ids_for_user(USER1).unwrap()); in test_add_remove()
516 assert_eq!(vec![VM_ID1, VM_ID2, VM_ID3], db.vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
517 assert_eq!(3, db.count_vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
518 assert_eq!(vec![VM_ID4], db.vm_ids_for_app(USER2, APP_B).unwrap()); in test_add_remove()
519 assert_eq!(1, db.count_vm_ids_for_app(USER2, APP_B).unwrap()); in test_add_remove()
520 assert_eq!(vec![VM_ID5], db.vm_ids_for_user(USER3).unwrap()); in test_add_remove()
521 assert_eq!(empty, db.vm_ids_for_user(USER_UNKNOWN).unwrap()); in test_add_remove()
522 assert_eq!(empty, db.vm_ids_for_app(USER1, APP_UNKNOWN).unwrap()); in test_add_remove()
523 assert_eq!(0, db.count_vm_ids_for_app(USER1, APP_UNKNOWN).unwrap()); in test_add_remove()
525 assert!(db.is_vm_id_for_app(&VM_ID1, USER1 as u32, APP_A as u32).unwrap()); in test_add_remove()
526 assert!(!db.is_vm_id_for_app(&VM_ID1, USER2 as u32, APP_A as u32).unwrap()); in test_add_remove()
527 assert!(!db.is_vm_id_for_app(&VM_ID1, USER1 as u32, APP_B as u32).unwrap()); in test_add_remove()
528 assert!(!db.is_vm_id_for_app(&VM_ID_UNKNOWN, USER1 as u32, APP_A as u32).unwrap()); in test_add_remove()
529 assert!(!db.is_vm_id_for_app(&VM_ID5, USER3 as u32, APP_A as u32).unwrap()); in test_add_remove()
530 assert!(db.is_vm_id_for_app(&VM_ID5, USER3 as u32, APP_C as u32).unwrap()); in test_add_remove()
532 db.delete_vm_ids(&[VM_ID2, VM_ID3]).unwrap(); in test_add_remove()
534 assert_eq!(vec![VM_ID1], db.vm_ids_for_user(USER1).unwrap()); in test_add_remove()
535 assert_eq!(vec![VM_ID1], db.vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
536 assert_eq!(1, db.count_vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
539 db.delete_vm_ids(&[VM_ID2, VM_ID3]).unwrap(); in test_add_remove()
541 assert_eq!(vec![VM_ID1], db.vm_ids_for_user(USER1).unwrap()); in test_add_remove()
542 assert_eq!(vec![VM_ID1], db.vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
543 assert_eq!(1, db.count_vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
545 db.add_vm_id(&VM_ID2, USER1, APP_A).unwrap(); in test_add_remove()
546 db.add_vm_id(&VM_ID3, USER1, APP_A).unwrap(); in test_add_remove()
548 assert_eq!(vec![VM_ID1, VM_ID2, VM_ID3], db.vm_ids_for_user(USER1).unwrap()); in test_add_remove()
549 assert_eq!(vec![VM_ID1, VM_ID2, VM_ID3], db.vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
550 assert_eq!(3, db.count_vm_ids_for_app(USER1, APP_A).unwrap()); in test_add_remove()
551 assert_eq!(vec![VM_ID4], db.vm_ids_for_app(USER2, APP_B).unwrap()); in test_add_remove()
552 assert_eq!(1, db.count_vm_ids_for_app(USER2, APP_B).unwrap()); in test_add_remove()
553 assert_eq!(vec![VM_ID5], db.vm_ids_for_user(USER3).unwrap()); in test_add_remove()
554 assert_eq!(empty, db.vm_ids_for_user(USER_UNKNOWN).unwrap()); in test_add_remove()
555 assert_eq!(empty, db.vm_ids_for_app(USER1, APP_UNKNOWN).unwrap()); in test_add_remove()
556 assert_eq!(0, db.count_vm_ids_for_app(USER1, APP_UNKNOWN).unwrap()); in test_add_remove()
560 db.get_all_owners().unwrap() in test_add_remove()
563 show_contents(&db); in test_add_remove()
568 let mut db = new_test_db(); in test_invalid_vm_id() localVariable
569 db.add_vm_id(&VM_ID3, USER1, APP_A).unwrap(); in test_invalid_vm_id()
570 db.add_vm_id(&VM_ID2, USER1, APP_A).unwrap(); in test_invalid_vm_id()
571 db.add_vm_id(&VM_ID1, USER1, APP_A).unwrap(); in test_invalid_vm_id()
574 assert_eq!(vec![VM_ID1, VM_ID2, VM_ID3], db.vm_ids_for_user(USER1).unwrap()); in test_invalid_vm_id()
577 db.conn in test_invalid_vm_id()
585 assert_eq!(vec![VM_ID1, VM_ID2, VM_ID3], db.vm_ids_for_user(USER1).unwrap()); in test_invalid_vm_id()
586 show_contents(&db); in test_invalid_vm_id()
591 let mut db = new_test_db_version(0); in test_remove_oldest_with_upgrade() localVariable
592 let version = db.schema_version().unwrap(); in test_remove_oldest_with_upgrade()
606 db.conn in test_remove_oldest_with_upgrade()
615 db.upgrade_tables_v0_v1().unwrap(); in test_remove_oldest_with_upgrade()
616 let version = db.schema_version().unwrap(); in test_remove_oldest_with_upgrade()
625 db.add_vm_id(&vm_id, USER1, APP_A).unwrap(); in test_remove_oldest_with_upgrade()
627 show_contents_for_app(&db, USER1, APP_A, 10); in test_remove_oldest_with_upgrade()
628 let got = db.oldest_vm_ids_for_app(USER1, APP_A, 10).unwrap(); in test_remove_oldest_with_upgrade()