Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

#41: update_one tests #52

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,4 +904,23 @@ mod tests {
assert!(new2 > old2);
assert!(new2 > new1);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea for a test case:

  1. Build the index of folder with paths e.g. root/A and root/B.
  2. Create file by path root/C.
  3. Call update_one("root/C", id).
    Two cases:
    a) id matches the content of new resource
    b) id does not
  4. What should be the result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, alright. Should it replace the current one or is it a new unittest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New one

#[test]
fn should_correctly_update_one_resource() {
run_test_and_clean_up(|path| {
create_file_at(path.clone(), Some(FILE_SIZE_1), Some(FILE_NAME_1));
create_file_at(path.clone(), Some(FILE_SIZE_2), Some(FILE_NAME_2));
let mut actual = ResourceIndex::build(path.clone());
let mut file_path = path.clone();
file_path.push(FILE_NAME_1);
let old_id = ResourceId {
data_size: FILE_SIZE_1,
crc32: CRC32_1,
};
let path_buf = CanonicalPathBuf::canonicalize(&file_path).unwrap();
let update = actual
.update_one(path_buf.clone(), old_id)
Copy link
Member

@kirillt kirillt Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm curious what happens if a user of the lib passes wrong old_id...

.expect("Should update one resource correctly");
});
Copy link
Member

@kirillt kirillt Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this current scenario, the update should be empty (nothing changed).

Probably reasoning with paths instead of files would be better here:

  • If we remove a file with id id1 and path path1 then the update is deleted(id1)
  • If we modify a file by path path1 so it's new id is id2 then the update is deleted(id1), added(id2)
  • If we rename/move a file with id1 from path1 to path2 then the update is deleted(id1), added(id1)

Please, double-check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notion of a "file" is confusing here because it is combination of path and content, but index works with paths and contents separately. A "resource" is an identified content, a "path" it's current location.

}
}