Skip to content

Commit 9c4bd29

Browse files
Improve test for env variables (#2409)
* Add test for AsyncLog respecting GIT_DIR * Mark test as serial * Mark additional test as serial * Unwrap result to get more info in error case --------- Co-authored-by: extrawurst <776816+extrawurst@users.noreply.github.com>
1 parent 1943988 commit 9c4bd29

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

asyncgit/src/revlog.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ mod tests {
331331
use std::time::Duration;
332332

333333
use crossbeam_channel::unbounded;
334+
use serial_test::serial;
335+
use tempfile::TempDir;
334336

335337
use crate::sync::tests::{debug_cmd_print, repo_init};
336338
use crate::sync::RepoPath;
@@ -339,6 +341,7 @@ mod tests {
339341
use super::AsyncLogResult;
340342

341343
#[test]
344+
#[serial]
342345
fn test_smoke_in_subdir() {
343346
let (_td, repo) = repo_init().unwrap();
344347
let root = repo.path().parent().unwrap();
@@ -366,6 +369,39 @@ mod tests {
366369
&tx_git,
367370
);
368371

369-
assert!(result.is_ok());
372+
assert_eq!(result.unwrap(), ());
373+
}
374+
375+
#[test]
376+
#[serial]
377+
fn test_env_variables() {
378+
let (_td, repo) = repo_init().unwrap();
379+
let git_dir = repo.path();
380+
381+
let (tx_git, _rx_git) = unbounded();
382+
383+
let empty_dir = TempDir::new().unwrap();
384+
let empty_path: RepoPath =
385+
empty_dir.path().to_str().unwrap().into();
386+
387+
let arc_current = Arc::new(Mutex::new(AsyncLogResult {
388+
commits: Vec::new(),
389+
duration: Duration::default(),
390+
}));
391+
let arc_background = Arc::new(AtomicBool::new(false));
392+
393+
std::env::set_var("GIT_DIR", git_dir);
394+
395+
let result = AsyncLog::fetch_helper_without_filter(
396+
// We pass an empty path, thus testing whether `GIT_DIR`, set above, is taken into account.
397+
&empty_path,
398+
&arc_current,
399+
&arc_background,
400+
&tx_git,
401+
);
402+
403+
std::env::remove_var("GIT_DIR");
404+
405+
assert_eq!(result.unwrap(), ());
370406
}
371407
}

0 commit comments

Comments
 (0)