-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Test the "current" migration created by the butane_test_helper due to | ||
//! all of the other tests in the butane/tests directory. | ||
#![cfg(test)] | ||
use butane::db::{BackendConnection, Connection}; | ||
use butane::migrations::{self, MemMigrations, Migration, Migrations, MigrationsMut}; | ||
use butane_test_helper::*; | ||
|
||
fn unmigrate(mut connection: Connection) { | ||
let base_dir = std::path::PathBuf::from(".butane"); | ||
let root = base_dir.join("migrations"); | ||
let mut disk_migrations = migrations::from_root(root); | ||
|
||
// this reproduces the migration created in butane_test_helper::setup_db | ||
let disk_current = disk_migrations.current(); | ||
let mut mem_migrations = MemMigrations::new(); | ||
let mem_current = mem_migrations.current(); | ||
migrations::copy_migration(disk_current, mem_current).unwrap(); | ||
|
||
assert!( | ||
disk_current.db().unwrap().tables().count() != 0, | ||
"No tables to migrate" | ||
); | ||
|
||
let backend_name = connection.backend_name(); | ||
let backend = butane::db::get_backend(backend_name).unwrap(); | ||
assert!( | ||
mem_migrations | ||
.create_migration(&nonempty::nonempty![backend], "init", None) | ||
.expect("expected to create migration without error"), | ||
"expected to create migration" | ||
); | ||
|
||
let migrations = mem_migrations.unapplied_migrations(&connection).unwrap(); | ||
assert_eq!(migrations.len(), 0); | ||
|
||
let migration = mem_migrations.latest().unwrap(); | ||
migration.downgrade(&mut connection).unwrap(); | ||
|
||
let migrations = mem_migrations.unapplied_migrations(&connection).unwrap(); | ||
assert_eq!(migrations.len(), 1); | ||
} | ||
testall!(unmigrate); |