-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xtask: generate katana test db #2271
Conversation
WalkthroughOhayo, sensei! This update enhances our Rust project workflow by introducing a new alias for generating test databases, adding configuration flexibility for specifying database directories, and establishing a module for managing database migrations. These changes streamline development, improve testing resource management, and optimize the testing environment, making it easier for everyone to work efficiently. Changes
Recent review detailsConfiguration used: .coderabbit.yaml Files ignored due to path filters (2)
Files selected for processing (3)
Files skipped from review due to trivial changes (1)
Files skipped from review as they are similar to previous changes (2)
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2271 +/- ##
==========================================
- Coverage 70.29% 69.78% -0.51%
==========================================
Files 342 342
Lines 45094 45116 +22
==========================================
- Hits 31698 31484 -214
- Misses 13396 13632 +236 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (1)
.github/workflows/ci.yml (1)
43-44
: Ohayo, sensei! Missing test database file detected.The file
spawn-and-move-test-db.tar.gz
is not present in the repository, which could cause failures in the CI workflow during the extraction step. Please ensure this file is added to the repository.
- Missing file:
spawn-and-move-test-db.tar.gz
Analysis chain
Verify test database file availability.
Ensure that the files
spawn-and-move-test-db.tar.gz
andtypes-test-db.tar.gz
are available in the expected location before extraction.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of the test database files in the repository. # Test: Search for the test database files. Expect: Files should be present. fd 'spawn-and-move-test-db.tar.gz' -t f fd 'types-test-db.tar.gz' -t fLength of output: 91
xtask/generate-test-db/src/main.rs
Outdated
/// Compresses the given db-path to a .tar.gz file. | ||
fn compress_db(db_path: &PathBuf, compressed_path: &str) { | ||
Command::new("tar") | ||
.args(["-czf", compressed_path, "-C", ".", &db_path.to_string_lossy().to_string()]) | ||
.status() | ||
.expect("Failed to compress test-db directory"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure error handling in compression.
The compress_db
function uses Command::new("tar")
without checking for errors. Consider adding error handling to ensure the compression process is robust.
fn compress_db(db_path: &PathBuf, compressed_path: &str) -> Result<()> {
let status = Command::new("tar")
.args(["-czf", compressed_path, "-C", ".", &db_path.to_string_lossy().to_string()])
.status()
.expect("Failed to compress test-db directory");
if !status.success() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
"Compression failed",
)));
}
Ok(())
}
/// Copies a directory into a temporary directory. | ||
/// | ||
/// # Returns | ||
/// | ||
/// A [`Utf8PathBuf`] object pointing to the copied directory. | ||
pub fn copy_tmp_dir(source_dir: &Utf8PathBuf) -> Utf8PathBuf { | ||
let temp_project_dir = Utf8PathBuf::from( | ||
assert_fs::TempDir::new().unwrap().to_path_buf().to_string_lossy().to_string(), | ||
); | ||
|
||
fn copy_dir_recursively(src: &PathBuf, dst: &PathBuf) -> io::Result<()> { | ||
if src.is_dir() { | ||
fs::create_dir_all(dst)?; | ||
for entry in fs::read_dir(src)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
let dst_path = dst.join(path.file_name().unwrap()); | ||
if path.is_dir() { | ||
copy_dir_recursively(&path, &dst_path)?; | ||
} else { | ||
fs::copy(&path, &dst_path)?; | ||
} | ||
} | ||
} else { | ||
fs::copy(src, dst)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
copy_dir_recursively(&source_dir.to_path_buf().into(), &temp_project_dir.to_path_buf().into()) | ||
.unwrap_or_else(|e| panic!("Failed to copy directory: {}", e)); | ||
|
||
temp_project_dir | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New utility function copy_tmp_dir
for directory copying.
The copy_tmp_dir
function provides a utility for copying directories to a temporary location. This is useful for setting up test environments. Ensure the error handling is robust, as the function currently panics on failure. Consider using Result
for error handling to provide more flexibility in managing errors.
pub fn copy_tmp_dir(source_dir: &Utf8PathBuf) -> Result<Utf8PathBuf, io::Error> {
let temp_project_dir = Utf8PathBuf::from(
assert_fs::TempDir::new().unwrap().to_path_buf().to_string_lossy().to_string(),
);
fn copy_dir_recursively(src: &PathBuf, dst: &PathBuf) -> io::Result<()> {
if src.is_dir() {
fs::create_dir_all(dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let path = entry.path();
let dst_path = dst.join(path.file_name().unwrap());
if path.is_dir() {
copy_dir_recursively(&path, &dst_path)?;
} else {
fs::copy(&path, &dst_path)?;
}
}
} else {
fs::copy(src, dst)?;
}
Ok(())
}
copy_dir_recursively(&source_dir.to_path_buf().into(), &temp_project_dir.to_path_buf().into())?;
Ok(temp_project_dir)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kariy for this. 🙏
run
cargo generate-test-db
to generate the test dbTODO: build the project before migrating
/~https://github.com/matklad/cargo-xtask
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores
.gitignore
to exclude temporary test database files.