2020-01-09 13:18:45 +00:00
|
|
|
//! Tests for the `cargo yank` command.
|
|
|
|
|
2020-01-14 07:15:29 +00:00
|
|
|
use std::fs;
|
2020-01-09 13:18:45 +00:00
|
|
|
|
2020-01-14 07:15:29 +00:00
|
|
|
use cargo_test_support::paths::CargoPathExt;
|
2020-01-09 13:18:45 +00:00
|
|
|
use cargo_test_support::project;
|
2020-03-06 23:05:12 +00:00
|
|
|
use cargo_test_support::registry;
|
2020-01-09 13:18:45 +00:00
|
|
|
|
|
|
|
fn setup(name: &str, version: &str) {
|
2020-03-06 23:05:12 +00:00
|
|
|
let dir = registry::api_path().join(format!("api/v1/crates/{}/{}", name, version));
|
2020-01-14 07:15:29 +00:00
|
|
|
dir.mkdir_p();
|
|
|
|
fs::write(dir.join("yank"), r#"{"ok": true}"#).unwrap();
|
2020-01-09 13:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
2022-04-19 21:44:39 +00:00
|
|
|
fn explicit_version() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = registry::init();
|
2020-01-09 13:18:45 +00:00
|
|
|
setup("foo", "0.0.1");
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
2020-01-09 13:18:45 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank --version 0.0.1")
|
|
|
|
.replace_crates_io(registry.index_url())
|
|
|
|
.run();
|
2020-01-21 00:09:39 +00:00
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank --undo --version 0.0.1")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2020-01-21 00:09:39 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2022-08-31 05:53:47 +00:00
|
|
|
" Updating crates.io index
|
2022-04-19 21:00:15 +00:00
|
|
|
Unyank foo@0.0.1
|
2021-02-27 20:38:17 +00:00
|
|
|
error: failed to undo a yank from the registry at file:///[..]
|
2020-01-21 00:09:39 +00:00
|
|
|
|
|
|
|
Caused by:
|
2020-01-22 00:19:59 +00:00
|
|
|
EOF while parsing a value at line 1 column 0",
|
2020-01-21 00:09:39 +00:00
|
|
|
)
|
|
|
|
.run();
|
2020-01-09 13:18:45 +00:00
|
|
|
}
|
2022-04-19 21:44:39 +00:00
|
|
|
|
2022-12-12 17:49:22 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn explicit_version_with_asymmetric() {
|
|
|
|
let registry = registry::RegistryBuilder::new()
|
|
|
|
.http_api()
|
|
|
|
.token(cargo_test_support::registry::Token::rfc_key())
|
|
|
|
.build();
|
|
|
|
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();
|
|
|
|
|
|
|
|
// The http_api server will check that the authorization is correct.
|
2022-12-13 23:46:20 +00:00
|
|
|
// If the authorization was not sent then we would get an unauthorized error.
|
2022-12-12 17:49:22 +00:00
|
|
|
p.cargo("yank --version 0.0.1")
|
2023-08-24 05:12:50 +00:00
|
|
|
.arg("-Zasymmetric-token")
|
|
|
|
.masquerade_as_nightly_cargo(&["asymmetric-token"])
|
2022-12-12 17:49:22 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("yank --undo --version 0.0.1")
|
2023-08-24 05:12:50 +00:00
|
|
|
.arg("-Zasymmetric-token")
|
|
|
|
.masquerade_as_nightly_cargo(&["asymmetric-token"])
|
2022-12-12 17:49:22 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2022-04-19 21:44:39 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn inline_version() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = registry::init();
|
2022-04-19 21:44:39 +00:00
|
|
|
setup("foo", "0.0.1");
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-19 21:44:39 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank foo@0.0.1")
|
|
|
|
.replace_crates_io(registry.index_url())
|
|
|
|
.run();
|
2022-04-19 21:44:39 +00:00
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank --undo foo@0.0.1")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2022-04-19 21:44:39 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2022-08-31 05:53:47 +00:00
|
|
|
" Updating crates.io index
|
2022-04-19 21:44:39 +00:00
|
|
|
Unyank foo@0.0.1
|
|
|
|
error: failed to undo a yank from the registry at file:///[..]
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
EOF while parsing a value at line 1 column 0",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn version_required() {
|
|
|
|
setup("foo", "0.0.1");
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-19 21:44:39 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank foo")
|
2022-04-19 21:44:39 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("error: `--version` is required")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn inline_version_without_name() {
|
|
|
|
setup("foo", "0.0.1");
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-19 21:44:39 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank @0.0.1")
|
2022-04-19 21:44:39 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("error: missing crate name for `@0.0.1`")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn inline_and_explicit_version() {
|
|
|
|
setup("foo", "0.0.1");
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-19 21:44:39 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("yank foo@0.0.1 --version 0.0.1")
|
2022-04-19 21:44:39 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("error: cannot specify both `@0.0.1` and `--version`")
|
|
|
|
.run();
|
|
|
|
}
|