]> git.proxmox.com Git - cargo.git/commitdiff
Update response handling to add tests for `cargo yank --undo`
authorTakayuki Nakata <f.seasons017@gmail.com>
Tue, 21 Jan 2020 00:09:39 +0000 (09:09 +0900)
committerTakayuki Nakata <f.seasons017@gmail.com>
Tue, 21 Jan 2020 00:09:39 +0000 (09:09 +0900)
Follow up 5e152863f.

crates/crates-io/lib.rs
tests/testsuite/yank.rs

index bd85e869748cec68faa422eff48794ff570f24e2..00cc3e0590ba1e96c7ce77b35f22a517ed178a44 100644 (file)
@@ -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> {
index 8b528046fd1194a4efc3534a9f473476e9d0707d..83c118be80d23ba65969c20499174e8169c55a36 100644 (file)
@@ -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();
 }