test with sub directories

This commit is contained in:
Nikita Galaiko 2023-11-30 13:18:04 +01:00 committed by GitButler
parent 10b325732f
commit 65f7bbbbd1

View File

@ -970,8 +970,9 @@ mod test {
}
// write another file into session
std::fs::write(project.path.join("test2.txt"), "hello world!").unwrap();
listener.handle("test2.txt", &project.id).unwrap();
std::fs::create_dir_all(project.path.join("one/two")).unwrap();
std::fs::write(project.path.join("one/two/test2.txt"), "hello world!").unwrap();
listener.handle("one/two/test2.txt", &project.id).unwrap();
let flushed_session = gb_repository
.flush(&project_repository, None)
@ -990,14 +991,19 @@ mod test {
.unwrap();
assert_eq!(
commit_reader.list_files(path::Path::new("wd")).unwrap(),
vec![path::Path::new("test.txt"), path::Path::new("test2.txt")]
vec![
path::Path::new("one/two/test2.txt"),
path::Path::new("test.txt"),
]
);
assert_eq!(
commit_reader.read(path::Path::new("wd/test.txt")).unwrap(),
reader::Content::UTF8("hello world!".to_string())
);
assert_eq!(
commit_reader.read(path::Path::new("wd/test2.txt")).unwrap(),
commit_reader
.read(path::Path::new("wd/one/two/test2.txt"))
.unwrap(),
reader::Content::UTF8("hello world!".to_string())
);
}
@ -1017,6 +1023,9 @@ mod test {
// write a file into session
std::fs::write(project.path.join("test.txt"), "hello world!").unwrap();
listener.handle("test.txt", &project.id).unwrap();
std::fs::create_dir_all(project.path.join("one/two")).unwrap();
std::fs::write(project.path.join("one/two/test2.txt"), "hello world!").unwrap();
listener.handle("one/two/test2.txt", &project.id).unwrap();
let flushed_session = gb_repository
.flush(&project_repository, None)
@ -1035,17 +1044,28 @@ mod test {
.unwrap();
assert_eq!(
commit_reader.list_files(path::Path::new("wd")).unwrap(),
vec![path::Path::new("test.txt")]
vec![
path::Path::new("one/two/test2.txt"),
path::Path::new("test.txt"),
]
);
assert_eq!(
commit_reader.read(path::Path::new("wd/test.txt")).unwrap(),
reader::Content::UTF8("hello world!".to_string())
);
assert_eq!(
commit_reader
.read(path::Path::new("wd/one/two/test2.txt"))
.unwrap(),
reader::Content::UTF8("hello world!".to_string())
);
}
// rm the files
std::fs::remove_file(project.path.join("test.txt")).unwrap();
listener.handle("test.txt", &project.id).unwrap();
std::fs::remove_file(project.path.join("one/two/test2.txt")).unwrap();
listener.handle("one/two/test.txt", &project.id).unwrap();
let flushed_session = gb_repository
.flush(&project_repository, None)
@ -1083,6 +1103,9 @@ mod test {
// write a file into session
std::fs::write(project.path.join("test.txt"), "hello world!").unwrap();
listener.handle("test.txt", &project.id).unwrap();
std::fs::create_dir_all(project.path.join("one/two")).unwrap();
std::fs::write(project.path.join("one/two/test2.txt"), "hello world!").unwrap();
listener.handle("one/two/test2.txt", &project.id).unwrap();
let flushed_session = gb_repository
.flush(&project_repository, None)
@ -1101,18 +1124,30 @@ mod test {
.unwrap();
assert_eq!(
commit_reader.list_files(path::Path::new("wd")).unwrap(),
vec![path::Path::new("test.txt")]
vec![
path::Path::new("one/two/test2.txt"),
path::Path::new("test.txt"),
]
);
assert_eq!(
commit_reader.read(path::Path::new("wd/test.txt")).unwrap(),
reader::Content::UTF8("hello world!".to_string())
);
assert_eq!(
commit_reader
.read(path::Path::new("wd/one/two/test2.txt"))
.unwrap(),
reader::Content::UTF8("hello world!".to_string())
);
}
// update the file
std::fs::write(project.path.join("test.txt"), "hello world!2").unwrap();
listener.handle("test.txt", &project.id).unwrap();
std::fs::write(project.path.join("one/two/test2.txt"), "hello world!2").unwrap();
listener.handle("one/two/test2.txt", &project.id).unwrap();
let flushed_session = gb_repository
.flush(&project_repository, None)
.unwrap()
@ -1130,12 +1165,21 @@ mod test {
.unwrap();
assert_eq!(
commit_reader.list_files(path::Path::new("wd")).unwrap(),
vec![path::Path::new("test.txt")]
vec![
path::Path::new("one/two/test2.txt"),
path::Path::new("test.txt"),
]
);
assert_eq!(
commit_reader.read(path::Path::new("wd/test.txt")).unwrap(),
reader::Content::UTF8("hello world!2".to_string())
);
assert_eq!(
commit_reader
.read(path::Path::new("wd/one/two/test2.txt"))
.unwrap(),
reader::Content::UTF8("hello world!2".to_string())
);
}
}
}