Skip to content

Commit

Permalink
Auto merge of #7818 - giraffate:add_some_tests, r=alexcrichton
Browse files Browse the repository at this point in the history
Add tests for `cargo owner -a/-r` / `cargo yank --undo`

Follow up 5e15286.

There were no tests for `cargo owner -a/-r` and `cargo yank --undo`. However, These commands in tests had empty response. So I also update response handling with reference to 7dd0f93.
  • Loading branch information
bors committed Jan 23, 2020
2 parents 8ee3d92 + a492cfc commit 6de33f0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 10 deletions.
86 changes: 76 additions & 10 deletions tests/testsuite/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,55 @@ use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::project;
use cargo_test_support::registry::{self, api_path, registry_url};

fn setup(name: &str) {
fn setup(name: &str, content: Option<&str>) {
let dir = api_path().join(format!("api/v1/crates/{}", name));
dir.mkdir_p();
fs::write(
dir.join("owners"),
r#"{
match content {
Some(body) => {
fs::write(dir.join("owners"), body).unwrap();
}
None => {}
}
}

#[cargo_test]
fn simple_list() {
registry::init();
let content = r#"{
"users": [
{
"id": 70,
"login": "github:rust-lang:core",
"name": "Core"
}
]
}"#,
)
.unwrap();
}"#;
setup("foo", Some(content));

let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("owner -l --index")
.arg(registry_url().to_string())
.run();
}

#[cargo_test]
fn simple_list() {
fn simple_add() {
registry::init();
setup("foo");
setup("foo", None);

let p = project()
.file(
Expand All @@ -44,7 +71,46 @@ fn simple_list() {
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("owner -l --index")
p.cargo("owner -a username --index")
.arg(registry_url().to_string())
.with_status(101)
.with_stderr(
" Updating `[..]` index
error: failed to invite owners to crate foo: EOF while parsing a value at line 1 column 0",
)
.run();
}

#[cargo_test]
fn simple_remove() {
registry::init();
setup("foo", None);

let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("owner -r username --index")
.arg(registry_url().to_string())
.with_status(101)
.with_stderr(
" Updating `[..]` index
Owner removing [\"username\"] from crate foo
error: failed to remove owners from crate foo
Caused by:
EOF while parsing a value at line 1 column 0",
)
.run();
}
13 changes: 13 additions & 0 deletions tests/testsuite/yank.rs
Original file line number Diff line number Diff line change
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:
EOF while parsing a value at line 1 column 0",
)
.run();
}

0 comments on commit 6de33f0

Please sign in to comment.