diff --git a/src/index.rs b/src/index.rs index 277bcc9..37397b5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -130,8 +130,18 @@ pub fn find(cache: &Path, key: &str) -> Result, Error> { })) } -pub fn delete(_cache: &Path, _key: &str) { - unimplemented!(); +pub fn delete(cache: &Path, key: &str) -> Result<(), Error> { + let inserter = Inserter { + cache: cache.to_path_buf(), + key: String::from(key), + size: None, + sri: None, + time: None, + metadata: None, + uid: None, + gid: None, + }; + inserter.commit() } pub fn ls(_cache: &Path) { @@ -242,4 +252,15 @@ mod tests { let dir = tmp.path().to_owned(); assert_eq!(find(&dir, "hello").unwrap(), None); } + + #[test] + fn delete_basic() { + let tmp = tempfile::tempdir().unwrap(); + let dir = tmp.path().to_owned(); + let sri: Integrity = "sha1-deadbeef".parse().unwrap(); + let time = 1_234_567; + insert(&dir, "hello", sri).time(time).commit().unwrap(); + delete(&dir, "hello").unwrap(); + assert_eq!(find(&dir, "hello").unwrap(), None); + } }