Skip to content

Commit

Permalink
Load credentials and add tests for yank and owner commands
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Jan 9, 2020
1 parent 4b70f14 commit 5e15286
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bin/cargo/commands/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
2 changes: 2 additions & 0 deletions src/bin/cargo/commands/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod net_config;
mod new;
mod offline;
mod out_dir;
mod owner;
mod package;
mod patch;
mod path;
Expand Down Expand Up @@ -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() {
Expand Down
53 changes: 53 additions & 0 deletions tests/testsuite/owner.rs
Original file line number Diff line number Diff line change
@@ -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();
}
47 changes: 47 additions & 0 deletions tests/testsuite/yank.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 5e15286

Please sign in to comment.