Skip to content

Commit

Permalink
Revert fixes of response handling and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Jan 22, 2020
1 parent 798f994 commit 58ae3d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 49 deletions.
53 changes: 7 additions & 46 deletions crates/crates-io/lib.rs
Expand Up @@ -149,41 +149,15 @@ impl Registry {
pub fn add_owners(&mut self, krate: &str, owners: &[&str]) -> Result<String> {
let body = serde_json::to_string(&OwnersReq { users: owners })?;
let body = self.put(&format!("/crates/{}/owners", krate), body.as_bytes())?;
let body = if body.is_empty() {
r#"{"ok":false,"msg":"response body is empty"}"#.parse()?
} else {
body
};
match serde_json::from_str::<OwnerResponse>(&body) {
Ok(response) => {
if response.ok {
Ok(response.msg)
} else {
bail!("{}", response.msg)
}
}
_ => bail!("failed to parse response body"),
}
assert!(serde_json::from_str::<OwnerResponse>(&body)?.ok);
Ok(serde_json::from_str::<OwnerResponse>(&body)?.msg)
}

pub fn remove_owners(&mut self, krate: &str, owners: &[&str]) -> Result<String> {
pub fn remove_owners(&mut self, krate: &str, owners: &[&str]) -> Result<()> {
let body = serde_json::to_string(&OwnersReq { users: owners })?;
let body = self.delete(&format!("/crates/{}/owners", krate), Some(body.as_bytes()))?;
let body = if body.is_empty() {
r#"{"ok":false,"msg":"response body is empty"}"#.parse()?
} else {
body
};
match serde_json::from_str::<OwnerResponse>(&body) {
Ok(response) => {
if response.ok {
Ok(response.msg)
} else {
bail!("{}", response.msg)
}
}
_ => bail!("failed to parse response body"),
}
assert!(serde_json::from_str::<OwnerResponse>(&body)?.ok);
Ok(())
}

pub fn list_owners(&mut self, krate: &str) -> Result<Vec<User>> {
Expand Down Expand Up @@ -298,21 +272,8 @@ impl Registry {

pub fn unyank(&mut self, krate: &str, version: &str) -> Result<()> {
let body = self.put(&format!("/crates/{}/{}/unyank", krate, version), &[])?;
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"),
}
assert!(serde_json::from_str::<R>(&body)?.ok);
Ok(())
}

fn put(&mut self, path: &str, b: &[u8]) -> Result<String> {
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/owner.rs
Expand Up @@ -76,7 +76,7 @@ fn simple_add() {
.with_status(101)
.with_stderr(
" Updating `[..]` index
error: failed to invite owners to crate foo: response body is empty",
error: failed to invite owners to crate foo: EOF while parsing a value at line 1 column 0",
)
.run();
}
Expand Down Expand Up @@ -110,7 +110,7 @@ fn simple_remove() {
error: failed to remove owners from crate foo
Caused by:
response body is empty",
EOF while parsing a value at line 1 column 0",
)
.run();
}
2 changes: 1 addition & 1 deletion tests/testsuite/yank.rs
Expand Up @@ -45,7 +45,7 @@ fn simple() {
error: failed to undo a yank
Caused by:
ok is false in response body",
EOF while parsing a value at line 1 column 0",
)
.run();
}

0 comments on commit 58ae3d0

Please sign in to comment.