Skip to content

Commit ebf1327

Browse files
committed
mutants: Check read_json passes back an error
1 parent 17f58f0 commit ebf1327

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/jsonio.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ mod tests {
133133
temp.close().unwrap();
134134
}
135135

136+
#[cfg(unix)]
137+
#[test]
138+
fn read_json_error_when_permission_denied() -> Result<()> {
139+
use std::os::unix::fs::PermissionsExt;
140+
let transport = Transport::temp();
141+
let f = std::fs::File::create(transport.local_path().unwrap().join("file"))?;
142+
let metadata = f.metadata()?;
143+
let mut perms = metadata.permissions();
144+
perms.set_mode(0);
145+
f.set_permissions(perms)?;
146+
read_json::<TestContents>(&transport, "file").expect_err("Read file with access denied");
147+
Ok(())
148+
}
149+
136150
#[test]
137151
fn read_json_is_none_for_nonexistent_files() {
138152
let transport = Transport::temp();

src/transport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ impl Transport {
240240
self.protocol.url()
241241
}
242242

243-
#[allow(unused)]
244-
fn local_path(&self) -> Option<PathBuf> {
243+
#[allow(unused)] // exposed for testing
244+
pub fn local_path(&self) -> Option<PathBuf> {
245245
self.protocol.local_path()
246246
}
247247
}

0 commit comments

Comments
 (0)