Skip to content

Commit ba574a6

Browse files
committed
add more unit tests
Signed-off-by: onur-ozkan <[email protected]>
1 parent c485ee7 commit ba574a6

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::{find_recent_config_change_ids, CONFIG_CHANGE_HISTORY};
2+
3+
#[test]
4+
fn test_find_recent_config_change_ids() {
5+
// If change-id is greater than the most recent one, result should be empty.
6+
assert!(find_recent_config_change_ids(usize::MAX).is_empty());
7+
8+
// There is no change-id equal to or less than 0, result should include the entire change history.
9+
assert_eq!(find_recent_config_change_ids(0).len(), CONFIG_CHANGE_HISTORY.len());
10+
}

src/bootstrap/src/tests/helpers.rs

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
use crate::utils::helpers::{check_cfg_arg, extract_beta_rev, hex_encode, make};
2-
use std::path::PathBuf;
1+
use crate::{
2+
utils::helpers::{
3+
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir,
4+
},
5+
Config,
6+
};
7+
use std::{
8+
fs::{self, remove_file, File},
9+
io::Write,
10+
path::PathBuf,
11+
};
312

413
#[test]
514
fn test_make() {
@@ -70,3 +79,34 @@ fn test_check_cfg_arg() {
7079
"--check-cfg=cfg(target_os,values(\"nixos\",\"nix2\"))"
7180
);
7281
}
82+
83+
#[test]
84+
fn test_program_out_of_date() {
85+
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
86+
let tempfile = config.tempdir().join(".tmp-stamp-file");
87+
File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();
88+
assert!(tempfile.exists());
89+
90+
// up-to-date
91+
assert!(!program_out_of_date(&tempfile, "dummy value"));
92+
// out-of-date
93+
assert!(program_out_of_date(&tempfile, ""));
94+
95+
remove_file(tempfile).unwrap();
96+
}
97+
98+
#[test]
99+
fn test_symlink_dir() {
100+
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
101+
let tempdir = config.tempdir().join(".tmp-dir");
102+
let link_path = config.tempdir().join(".tmp-link");
103+
104+
fs::create_dir_all(&tempdir).unwrap();
105+
symlink_dir(&config, &tempdir, &link_path).unwrap();
106+
107+
let link_source = fs::read_link(&link_path).unwrap();
108+
assert_eq!(link_source, tempdir);
109+
110+
fs::remove_dir(tempdir).unwrap();
111+
fs::remove_file(link_path).unwrap();
112+
}

src/bootstrap/src/utils/change_tracker.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
//! with the goal of keeping developers synchronized with important modifications in
33
//! the bootstrap.
44
5+
#[cfg(test)]
6+
#[path = "../tests/change_tracker.rs"]
7+
mod tests;
8+
59
#[derive(Clone, Debug)]
610
pub struct ChangeInfo {
711
/// Represents the ID of PR caused major change on bootstrap.

0 commit comments

Comments
 (0)