Skip to content

Commit

Permalink
Update response handling to add tests for cargo yank --undo
Browse files Browse the repository at this point in the history
Follow up 5e15286.
  • Loading branch information
giraffate committed Jan 21, 2020
1 parent e632bdb commit 798f994
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/crates-io/lib.rs
Expand Up @@ -298,8 +298,21 @@ impl Registry {

pub fn unyank(&mut self, krate: &str, version: &str) -> Result<()> {
let body = self.put(&format!("/crates/{}/{}/unyank", krate, version), &[])?;
assert!(serde_json::from_str::<R>(&body)?.ok);
Ok(())
let body = if body.is_empty() {
r#"{"ok":false}"#.parse()?
} else {
body
};
match serde_json::from_str::<R>(&body) {
Ok(response) => {
if response.ok {
Ok(())
} else {
bail!("ok is false in response body")
}
}
_ => bail!("failed to parse response body"),
}
}

fn put(&mut self, path: &str, b: &[u8]) -> Result<String> {
Expand Down
13 changes: 13 additions & 0 deletions tests/testsuite/yank.rs
Expand Up @@ -35,4 +35,17 @@ fn simple() {
p.cargo("yank --vers 0.0.1 --index")
.arg(registry_url().to_string())
.run();

p.cargo("yank --undo --vers 0.0.1 --index")
.arg(registry_url().to_string())
.with_status(101)
.with_stderr(
" Updating `[..]` index
Unyank foo:0.0.1
error: failed to undo a yank
Caused by:
ok is false in response body",
)
.run();
}

0 comments on commit 798f994

Please sign in to comment.