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

Conversation

oluiscabral
Copy link
Collaborator

@oluiscabral oluiscabral commented Oct 14, 2023

};
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...

let update = actual
.update_one(path_buf.clone(), 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.

@@ -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

@kirillt kirillt changed the title update_one tests #41: update_one tests Oct 16, 2023
@kirillt
Copy link
Member

kirillt commented Oct 16, 2023

Should we create new struct for the error Collision("New content has the same id")? Word "Collision" can be confusing here since it can be caused not only by hash collision but also by wrong caller's code. The idea is that update_one is a quick way to update index without checking all resources in situations when the caller knows for sure that it was changed. E.g. when the caller edits the resource.

So, if the caller doesn't have information that the resource changed, it's a mistake to call this method. But if the resource was changed indeed (timestamp must be changed, too) and new content has same size and same CRC-32 hash — then it's a collision indeed.

We can also split single error into two different errors for clarity, depending on was the timestamp changed or not.

@kirillt
Copy link
Member

kirillt commented Jan 21, 2024

Superseded by #72

@kirillt kirillt closed this Jan 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants