Skip to content

Commit 798f994

Browse files
committed
Update response handling to add tests for cargo yank --undo
Follow up 5e15286.
1 parent e632bdb commit 798f994

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

crates/crates-io/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,21 @@ impl Registry {
298298

299299
pub fn unyank(&mut self, krate: &str, version: &str) -> Result<()> {
300300
let body = self.put(&format!("/crates/{}/{}/unyank", krate, version), &[])?;
301-
assert!(serde_json::from_str::<R>(&body)?.ok);
302-
Ok(())
301+
let body = if body.is_empty() {
302+
r#"{"ok":false}"#.parse()?
303+
} else {
304+
body
305+
};
306+
match serde_json::from_str::<R>(&body) {
307+
Ok(response) => {
308+
if response.ok {
309+
Ok(())
310+
} else {
311+
bail!("ok is false in response body")
312+
}
313+
}
314+
_ => bail!("failed to parse response body"),
315+
}
303316
}
304317

305318
fn put(&mut self, path: &str, b: &[u8]) -> Result<String> {

tests/testsuite/yank.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ fn simple() {
3535
p.cargo("yank --vers 0.0.1 --index")
3636
.arg(registry_url().to_string())
3737
.run();
38+
39+
p.cargo("yank --undo --vers 0.0.1 --index")
40+
.arg(registry_url().to_string())
41+
.with_status(101)
42+
.with_stderr(
43+
" Updating `[..]` index
44+
Unyank foo:0.0.1
45+
error: failed to undo a yank
46+
47+
Caused by:
48+
ok is false in response body",
49+
)
50+
.run();
3851
}

0 commit comments

Comments
 (0)