MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / test_update_migrator

Function test_update_migrator

sea-orm-cli/src/commands/migrate.rs:298–330  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

296
297 #[test]
298 fn test_update_migrator() {
299 let migration_name = "test_name";
300 let migration_dir = "/tmp/sea_orm_cli_test_update_migrator/";
301 fs::create_dir_all(format!("{migration_dir}src")).unwrap();
302 let migrator_filepath = Path::new(migration_dir).join("src").join("lib.rs");
303 fs::copy("./template/migration/src/lib.rs", &migrator_filepath).unwrap();
304 update_migrator(migration_name, migration_dir).unwrap();
305 assert!(&migrator_filepath.exists());
306 let migrator_content = fs::read_to_string(&migrator_filepath).unwrap();
307 let mod_regex = Regex::new(r"mod (?P<name>\w+);").unwrap();
308 let migrations: Vec<&str> = mod_regex
309 .captures_iter(&migrator_content)
310 .map(|cap| cap.name("name").unwrap().as_str())
311 .collect();
312 assert_eq!(migrations.len(), 2);
313 assert_eq!(
314 *migrations.first().unwrap(),
315 "m20220101_000001_create_table"
316 );
317 assert_eq!(migrations.last().unwrap(), &migration_name);
318 let boxed_regex = Regex::new(r"Box::new\((?P<name>\S+)::Migration\)").unwrap();
319 let migrations: Vec<&str> = boxed_regex
320 .captures_iter(&migrator_content)
321 .map(|cap| cap.name("name").unwrap().as_str())
322 .collect();
323 assert_eq!(migrations.len(), 2);
324 assert_eq!(
325 *migrations.first().unwrap(),
326 "m20220101_000001_create_table"
327 );
328 assert_eq!(migrations.last().unwrap(), &migration_name);
329 fs::remove_dir_all("/tmp/sea_orm_cli_test_update_migrator/").unwrap();
330 }
331}

Callers

nothing calls this directly

Calls 6

update_migratorFunction · 0.85
unwrapMethod · 0.80
joinMethod · 0.80
newFunction · 0.50
as_strMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected