aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/store/sqlite.rs168
1 files changed, 168 insertions, 0 deletions
diff --git a/src/app/store/sqlite.rs b/src/app/store/sqlite.rs
index 258a12f..77c45c7 100644
--- a/src/app/store/sqlite.rs
+++ b/src/app/store/sqlite.rs
@@ -508,4 +508,172 @@ mod tests {
assert!(res.is_ok());
assert!(context.connection.is_some());
}
+
+ #[test]
+ fn exec_migration_list_init() {
+ let mut context = SQLiteStore::default();
+ let conn_path = context.location.clone();
+ let conn = sqlite::open(conn_path).unwrap();
+ context.connection = Option::Some(conn);
+
+ let res = context.exec_migration_list();
+ assert!(res.is_ok());
+
+ let migration_list = res.unwrap();
+ assert!(migration_list.is_empty());
+ }
+
+ #[test]
+ fn exec_migration_list_post_migration() {
+ let mut context = SQLiteStore::default();
+ let conn_path = context.location.clone();
+ let conn = sqlite::open(conn_path).unwrap();
+ context.connection = Option::Some(conn);
+
+ let migrations = context.run_migrations();
+ assert!(migrations.is_ok());
+
+ let res = context.exec_migration_list();
+ assert!(res.is_ok());
+
+ let migration_list = res.unwrap();
+ assert!(!migration_list.is_empty());
+ }
+
+ #[test]
+ fn run_migrations_all() {
+ let mut context = SQLiteStore::default();
+ let conn_path = context.location.clone();
+ let conn = sqlite::open(conn_path).unwrap();
+ context.connection = Option::Some(conn);
+
+ {
+ let mig_list_before = context
+ .get_connection()
+ .unwrap()
+ .prepare(SQLiteStore::MIGRATION_CONTROL_SELECT_QUERY);
+
+ // select query fails; migration_control table hasn't been added yet
+ assert!(mig_list_before.is_err());
+ };
+
+ let res = context.run_migrations();
+ assert!(res.is_ok());
+
+ let mig_list_after = context.exec_migration_list();
+ assert!(mig_list_after.is_ok());
+ let a = mig_list_after.unwrap();
+
+ let file_list = db::get_migration_scripts();
+ assert!(file_list.is_ok());
+
+ // assert there are migrations, and the end result of migrations is the same
+ let b = file_list.unwrap();
+ assert!(!b.is_empty());
+ assert_eq!(b.len(), a.len());
+
+ // All migrations are in the file list
+ assert!(a.iter().all(|migration| {
+ b.iter()
+ .any(|file| file.filename == migration.migration_filename)
+ }));
+ // All files are in the migration list
+ assert!(b.iter().all(|file| {
+ a.iter()
+ .any(|migration| file.filename == migration.migration_filename)
+ }));
+ }
+
+ #[test]
+ fn run_migrations_partial() {
+ let mut context = SQLiteStore::default();
+ let conn_path = context.location.clone();
+ let conn = sqlite::open(conn_path).unwrap();
+ context.connection = Option::Some(conn);
+
+ // Init migration table
+ let migration_control = context.exec_migration_list();
+ assert!(migration_control.is_ok());
+
+ // Run first migration
+ let file_list = db::get_migration_scripts();
+ assert!(file_list.is_ok());
+ let mig_list = file_list.unwrap();
+ assert!(mig_list.len() > 1);
+ let first_mig = &mig_list[0];
+ let res = context.run_and_insert_migration(0_usize, first_mig);
+ assert!(res.is_ok());
+
+ // Get list of run migrations; assert first one is in there
+ let mig_list_before = context.exec_migration_list();
+ assert!(mig_list_before.is_ok());
+ let a = mig_list_before.unwrap();
+ assert_eq!(a.len(), 1);
+ assert_eq!(a[0].migration_id, 0_usize);
+ assert_eq!(a[0].migration_filename, first_mig.filename);
+
+ // Run the rest
+ let res = context.run_migrations();
+ assert!(res.is_ok());
+
+ let mig_list_after = context.exec_migration_list();
+ assert!(mig_list_after.is_ok());
+ let b = mig_list_after.unwrap();
+ assert!(b.len() > a.len());
+ assert_eq!(mig_list.len(), b.len() - a.len() + 1);
+
+ // All final migrations are in the file list
+ assert!(b.iter().all(|migration| {
+ mig_list
+ .iter()
+ .any(|file| file.filename == migration.migration_filename)
+ }));
+ // All files are in the final migration list
+ assert!(mig_list.iter().all(|file| {
+ b.iter()
+ .any(|migration| file.filename == migration.migration_filename)
+ }));
+ }
+
+ #[test]
+ fn get_accounts_empty() {
+ let mut context = SQLiteStore::default();
+
+ let init = context.init();
+ assert!(init.is_ok());
+
+ let res = context.get_accounts();
+ assert!(res.is_ok());
+
+ let accounts = res.unwrap();
+ assert!(accounts.is_empty());
+ }
+
+ #[test]
+ fn get_symbols_empty() {
+ let mut context = SQLiteStore::default();
+
+ let init = context.init();
+ assert!(init.is_ok());
+
+ let res = context.get_symbols();
+ assert!(res.is_ok());
+
+ let symbols = res.unwrap();
+ assert!(symbols.is_empty());
+ }
+
+ #[test]
+ fn get_events_empty() {
+ let mut context = SQLiteStore::default();
+
+ let init = context.init();
+ assert!(init.is_ok());
+
+ let res = context.get_events();
+ assert!(res.is_ok());
+
+ let events = res.unwrap();
+ assert!(events.is_empty());
+ }
}