diff --git a/src/bin/cargo/commands/owner.rs b/src/bin/cargo/commands/owner.rs index e9d5d85213b..e7ac30da58a 100644 --- a/src/bin/cargo/commands/owner.rs +++ b/src/bin/cargo/commands/owner.rs @@ -39,6 +39,8 @@ Explicitly named owners can also modify the set of owners, so take care! } pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { + config.load_credentials()?; + let registry = args.registry(config)?; let opts = OwnersOptions { krate: args.value_of("crate").map(|s| s.to_string()), diff --git a/src/bin/cargo/commands/yank.rs b/src/bin/cargo/commands/yank.rs index 3079c544fb9..35ded936911 100644 --- a/src/bin/cargo/commands/yank.rs +++ b/src/bin/cargo/commands/yank.rs @@ -29,6 +29,8 @@ crates to be locked to any yanked version. } pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { + config.load_credentials()?; + let registry = args.registry(config)?; ops::yank( diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 9c1c1913e36..bbea3cc022e 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -68,6 +68,7 @@ mod net_config; mod new; mod offline; mod out_dir; +mod owner; mod package; mod patch; mod path; @@ -106,6 +107,7 @@ mod verify_project; mod version; mod warn_on_failure; mod workspaces; +mod yank; #[cargo_test] fn aaa_trigger_cross_compile_disabled_check() { diff --git a/tests/testsuite/owner.rs b/tests/testsuite/owner.rs new file mode 100644 index 00000000000..77fa8865735 --- /dev/null +++ b/tests/testsuite/owner.rs @@ -0,0 +1,53 @@ +//! Tests for the `cargo owner` command. + +use std::fs::{self, File}; +use std::io::prelude::*; + +use cargo_test_support::project; +use cargo_test_support::registry::{self, api_path, registry_url}; + +fn setup(name: &str) { + fs::create_dir_all(&api_path().join(format!("api/v1/crates/{}", name))).unwrap(); + + let dest = api_path().join(format!("api/v1/crates/{}/owners", name)); + + let content = r#"{ + "users": [ + { + "id": 70, + "login": "github:rust-lang:core", + "name": "Core" + } + ] + }"#; + + File::create(&dest) + .unwrap() + .write_all(content.as_bytes()) + .unwrap(); +} + +#[cargo_test] +fn simple_list() { + registry::init(); + setup("foo"); + + 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(); +} diff --git a/tests/testsuite/yank.rs b/tests/testsuite/yank.rs new file mode 100644 index 00000000000..f836ff76d63 --- /dev/null +++ b/tests/testsuite/yank.rs @@ -0,0 +1,47 @@ +//! Tests for the `cargo yank` command. + +use std::fs::{self, File}; +use std::io::prelude::*; + +use cargo_test_support::project; +use cargo_test_support::registry::{self, api_path, registry_url}; + +fn setup(name: &str, version: &str) { + fs::create_dir_all(&api_path().join(format!("api/v1/crates/{}/{}", name, version))).unwrap(); + + let dest = api_path().join(format!("api/v1/crates/{}/{}/yank", name, version)); + + let content = r#"{ + "ok": true + }"#; + + File::create(&dest) + .unwrap() + .write_all(content.as_bytes()) + .unwrap(); +} + +#[cargo_test] +fn simple() { + registry::init(); + setup("foo", "0.0.1"); + + 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("yank --vers 0.0.1 --index") + .arg(registry_url().to_string()) + .run(); +}