Skip to content

Commit

Permalink
feat: improve migration tests for sea-orm
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoeori committed Jan 5, 2025
1 parent 565efc0 commit 44a44a1
Showing 1 changed file with 44 additions and 37 deletions.
81 changes: 44 additions & 37 deletions packages/storage/shield-sea-orm/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,51 @@ fn example_path() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../examples/sea-orm")
}

#[test]
pub fn mysql() {
assert!(Command::new("sea-orm-cli")
.arg("migrate")
.arg("fresh")
.arg("-u")
.arg("mysql://shield:shield@localhost:13306/shield")
.arg("-d")
.arg(example_path())
.status()
.expect("MySQL migration should succeed.")
.success());
}
const BACKENDS: &[(&str, &str)] = &[
("mysql", "mysql://shield:shield@localhost:13306/shield"),
(
"postgresql",
"postgres://shield:shield@localhost:15432/shield",
),
("sqlite", "sqlite:///tmp/shield-seaorm.sqlite?mode=rwc"),
];

#[test]
pub fn postgresql() {
assert!(Command::new("sea-orm-cli")
.arg("migrate")
.arg("fresh")
.arg("-u")
.arg("postgres://shield:shield@localhost:15432/shield")
.arg("-d")
.arg(example_path())
.status()
.expect("MySQL migration should succeed.")
.success());
}
pub fn migrations() {
for (backend, url) in BACKENDS {
assert!(Command::new("sea-orm-cli")
.arg("migrate")
.arg("fresh")
.arg("-u")
.arg(url)
.arg("-d")
.arg(example_path())
.status()
.unwrap_or_else(|_| panic!("{} initial migrations should succeed.", backend))
.success());

#[test]
pub fn sqlite() {
assert!(Command::new("sea-orm-cli")
.arg("migrate")
.arg("fresh")
.arg("-u")
.arg("sqlite:///tmp/shield-seaorm.sqlite?mode=rwc")
.arg("-d")
.arg(example_path())
.status()
.expect("MySQL migration should succeed.")
.success());
// Check down migrations
assert!(Command::new("sea-orm-cli")
.arg("migrate")
.arg("refresh")
.arg("-u")
.arg(url)
.arg("-d")
.arg(example_path())
.status()
.unwrap_or_else(|_| panic!("{} down migrations should succeed.", backend))
.success());

// Cleanup
assert!(Command::new("sea-orm-cli")
.arg("migrate")
.arg("reset")
.arg("-u")
.arg(url)
.arg("-d")
.arg(example_path())
.status()
.unwrap_or_else(|_| panic!("{} cleanup should succeed.", backend))
.success());
}
}

0 comments on commit 44a44a1

Please sign in to comment.