Skip to content

Commit 90f29a0

Browse files
author
Stephan Dilly
committed
added tests
1 parent 38b4253 commit 90f29a0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

asyncgit/src/sync/utils.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,43 @@ mod tests {
145145

146146
commit(repo_path, "commit msg");
147147
}
148+
149+
#[test]
150+
fn test_stage_add_smoke() {
151+
let file_path = Path::new("foo");
152+
let (_td, repo) = repo_init_empty();
153+
let root = repo.path().parent().unwrap();
154+
let repo_path = root.as_os_str().to_str().unwrap();
155+
156+
assert_eq!(stage_add(repo_path, file_path), false);
157+
}
158+
159+
#[test]
160+
fn test_staging_one_file() {
161+
let file_path = Path::new("file1.txt");
162+
let (_td, repo) = repo_init();
163+
let root = repo.path().parent().unwrap();
164+
let repo_path = root.as_os_str().to_str().unwrap();
165+
166+
let status_count = |s: StatusType| -> usize {
167+
get_status(repo_path, s).len()
168+
};
169+
170+
File::create(&root.join(file_path))
171+
.unwrap()
172+
.write_all(b"test file1 content")
173+
.unwrap();
174+
175+
File::create(&root.join(Path::new("file2.txt")))
176+
.unwrap()
177+
.write_all(b"test file2 content")
178+
.unwrap();
179+
180+
assert_eq!(status_count(StatusType::WorkingDir), 2);
181+
182+
assert_eq!(stage_add(repo_path, file_path), true);
183+
184+
assert_eq!(status_count(StatusType::WorkingDir), 1);
185+
assert_eq!(status_count(StatusType::Stage), 1);
186+
}
148187
}

0 commit comments

Comments
 (0)