Skip to content

Commit 5e15286

Browse files
committed
Load credentials and add tests for yank and owner commands
1 parent 4b70f14 commit 5e15286

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

src/bin/cargo/commands/owner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Explicitly named owners can also modify the set of owners, so take care!
3939
}
4040

4141
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
42+
config.load_credentials()?;
43+
4244
let registry = args.registry(config)?;
4345
let opts = OwnersOptions {
4446
krate: args.value_of("crate").map(|s| s.to_string()),

src/bin/cargo/commands/yank.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ crates to be locked to any yanked version.
2929
}
3030

3131
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
32+
config.load_credentials()?;
33+
3234
let registry = args.registry(config)?;
3335

3436
ops::yank(

tests/testsuite/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod net_config;
6868
mod new;
6969
mod offline;
7070
mod out_dir;
71+
mod owner;
7172
mod package;
7273
mod patch;
7374
mod path;
@@ -106,6 +107,7 @@ mod verify_project;
106107
mod version;
107108
mod warn_on_failure;
108109
mod workspaces;
110+
mod yank;
109111

110112
#[cargo_test]
111113
fn aaa_trigger_cross_compile_disabled_check() {

tests/testsuite/owner.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//! Tests for the `cargo owner` command.
2+
3+
use std::fs::{self, File};
4+
use std::io::prelude::*;
5+
6+
use cargo_test_support::project;
7+
use cargo_test_support::registry::{self, api_path, registry_url};
8+
9+
fn setup(name: &str) {
10+
fs::create_dir_all(&api_path().join(format!("api/v1/crates/{}", name))).unwrap();
11+
12+
let dest = api_path().join(format!("api/v1/crates/{}/owners", name));
13+
14+
let content = r#"{
15+
"users": [
16+
{
17+
"id": 70,
18+
"login": "github:rust-lang:core",
19+
"name": "Core"
20+
}
21+
]
22+
}"#;
23+
24+
File::create(&dest)
25+
.unwrap()
26+
.write_all(content.as_bytes())
27+
.unwrap();
28+
}
29+
30+
#[cargo_test]
31+
fn simple_list() {
32+
registry::init();
33+
setup("foo");
34+
35+
let p = project()
36+
.file(
37+
"Cargo.toml",
38+
r#"
39+
[project]
40+
name = "foo"
41+
version = "0.0.1"
42+
authors = []
43+
license = "MIT"
44+
description = "foo"
45+
"#,
46+
)
47+
.file("src/main.rs", "fn main() {}")
48+
.build();
49+
50+
p.cargo("owner -l --index")
51+
.arg(registry_url().to_string())
52+
.run();
53+
}

tests/testsuite/yank.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Tests for the `cargo yank` command.
2+
3+
use std::fs::{self, File};
4+
use std::io::prelude::*;
5+
6+
use cargo_test_support::project;
7+
use cargo_test_support::registry::{self, api_path, registry_url};
8+
9+
fn setup(name: &str, version: &str) {
10+
fs::create_dir_all(&api_path().join(format!("api/v1/crates/{}/{}", name, version))).unwrap();
11+
12+
let dest = api_path().join(format!("api/v1/crates/{}/{}/yank", name, version));
13+
14+
let content = r#"{
15+
"ok": true
16+
}"#;
17+
18+
File::create(&dest)
19+
.unwrap()
20+
.write_all(content.as_bytes())
21+
.unwrap();
22+
}
23+
24+
#[cargo_test]
25+
fn simple() {
26+
registry::init();
27+
setup("foo", "0.0.1");
28+
29+
let p = project()
30+
.file(
31+
"Cargo.toml",
32+
r#"
33+
[project]
34+
name = "foo"
35+
version = "0.0.1"
36+
authors = []
37+
license = "MIT"
38+
description = "foo"
39+
"#,
40+
)
41+
.file("src/main.rs", "fn main() {}")
42+
.build();
43+
44+
p.cargo("yank --vers 0.0.1 --index")
45+
.arg(registry_url().to_string())
46+
.run();
47+
}

0 commit comments

Comments
 (0)